Newton's Fractals in Python
Newton's Fractals in Python
Lab 3
Joshua Cook
October 28, 2014
Preliminaries
0.1
p(zn )
p0 (zn )
where a is any complex number. The special choice a = 1 corresponds to the Newton fractal.
The fixed points of this map are stable when a lies inside the disk of radius 1 centered at 1. When a is outside
this disk, the fixed points are locally unstable, however the map still exhibits a fractal structure in the sense
of the Julia set. If p is a polynomial of degree n, then the sequence zn is bounded provided that a is inside a
disk of radius n centered at n.
More generally, Newtons fractal is a special case of a Julia set.
0.2
Import Statement
Numerical Analysis
Lab 3
Joshua Cook
October 28, 2014
1
Write a Python function that takes as input the integer n and returns a 1d numpy array of length n holding
the n roots of unity; that is, the n roots of the polynomial
zn 1 = 0
def unity_roots(n):
roots = np.zeros((n,1), dtype=complex)
for i in range(n):
theta = 2*i*math.pi/n
re = math.cos(theta)
im = math.sin(theta)
roots[i] = re + im*1j
return roots
Numerical Analysis
Lab 3
Joshua Cook
October 28, 2014
2
Write a Python function named nfractal that takes as input four arguments: K, pixel, tol, and n, and
1. generates a mesh of the complex plane consisting of pixel points along the x-axis and 0.75*pixel
points along the x-axis, with x, y [1.5, 1.5].
k)
2. applies the iteration zk+1 = zk a pp(z
0 (z ) to each z = x + iy on the mesh K times and records the number
k
of times that the iterated value is within tol distance to one of the roots of the polynomial p(z).
3. colors each point in the mesh grid according to the number of times it is within a distance tol of one
of the roots of the polynomial p(z).
2.1
Define Function
Numerical Analysis
Lab 3
Joshua Cook
October 28, 2014
Numerical Analysis
Lab 3
Joshua Cook
October 28, 2014
Numerical Analysis
Lab 3
Joshua Cook
October 28, 2014
Numerical Analysis
Lab 3
Joshua Cook
October 28, 2014
Numerical Analysis
Lab 3
Joshua Cook
October 28, 2014
Numerical Analysis
Lab 3
Joshua Cook
October 28, 2014
Numerical Analysis
Lab 3
Joshua Cook
October 28, 2014
Numerical Analysis
Lab 3
Joshua Cook
October 28, 2014
Numerical Analysis
Lab 3
G = G *(510/K)
B = B *(510/K)
im[:,:,0] = R
im[:,:,1] = G
im[:,:,2] = B
plt.imshow(im)
return Re, Im, B
frac = nfractal(60,1000,10E-6,2)
Joshua Cook
October 28, 2014
Numerical Analysis
Lab 3
Joshua Cook
October 28, 2014
Numerical Analysis
Lab 3
Joshua Cook
October 28, 2014
Numerical Analysis
Lab 3
Joshua Cook
October 28, 2014
Numerical Analysis
Lab 3
Joshua Cook
October 28, 2014
Numerical Analysis
Lab 3
Joshua Cook
October 28, 2014
Numerical Analysis
Lab 3
Joshua Cook
October 28, 2014
Numerical Analysis
Lab 3
Joshua Cook
October 28, 2014