Mandelbrot set: Difference between revisions

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

edits