Week 11: Exercise Solutions

Exercise 11.1

1.

import numpy as np
import matplotlib.pyplot as plt

theta = np.linspace(0, 2*np.pi, 100)

plt.plot(0.9*np.cos(theta), 0.4*np.sin(theta))
plt.gca().set_aspect("equal")
plt.axis([-1.1, 1.1, -1.1, 1.1])
plt.show()

2.

import numpy as np
import matplotlib.pyplot as plt

theta = np.linspace(0, 12, 100)

plt.plot(theta*np.cos(theta), theta*np.sin(theta))
plt.gca().set_aspect("equal")
plt.axis([-11, 11, -11, 11])
plt.show()

Exercise 11.2

import matplotlib.pyplot as plt

# Plot the vertical lines
for i in range(9):
    plt.plot([i, i], [0, 8], color="blue")

# Plot the horizontal lines
for i in range(9):
    plt.plot([0, 8], [i, i], color="blue")

plt.gca().set_aspect("equal")
plt.axis([-1, 9, -1, 9])
plt.show()

Exercise 11.3

Add the draw_circle() function to the beginning of the program and add the following after the drawing of the spokes.

for radius in range(1, 10):
    draw_circle([0, 0], radius/10)

Exercise 11.5

Change the 5 in Line 7 to a 10, and add the following at Line 12, indented eight spaces.

        size[i] = 1