Mandelbrot set: Difference between revisions
Content added Content deleted
(→{{header|Python}}: a more mathematical spelling, as the students are used to it.) |
m (→{{header|Python}}: Added a few comments.) |
||
Line 6,394: | Line 6,394: | ||
import matplotlib.pyplot as plt |
import matplotlib.pyplot as plt |
||
p = 100 # points per unit |
|||
n = 50 # number of iterations |
n = 50 # number of iterations |
||
⚫ | |||
x = np.linspace(-2.5, 1.5, |
x = np.linspace(-2.5, 1.5, 4*p+1) |
||
y = np.linspace(-1.5, 1.5, |
y = np.linspace(-1.5, 1.5, 3*p+1) |
||
A, B = np.meshgrid(x, y) |
A, B = np.meshgrid(x, y) |
||
C = A + B |
C = A + B*1j |
||
Z = np.zeros_like(C) |
Z = np.zeros_like(C) # initial values are always zero |
||
T = np.zeros(C.shape) |
T = np.zeros(C.shape) # table of escape times |
||
⚫ | |||
M = abs(Z) < r # mark all points that have not escaped |
|||
M = abs(Z) < r |
|||
for k in range(n): |
for k in range(n): |
||
Z[M] = Z[M] |
Z[M] = Z[M]**2 + C[M] |
||
M = abs(Z) < r |
M = abs(Z) < r |
||
T[M] = k + 1 |
T[M] = k + 1 |