In [ ]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from scipy.interpolate import interp1d
from scipy.optimize import curve_fit, fsolve


## Newton fractal¶

• Consider the solution to the simple fourth order polynomial: $x^4−1=0$.
• There are four roots at $x=1,−1,i,−i$.
• Newton's method starts at a given guess $x_0$, then updates that guess.
• If we guess some point in the complex plane, Newton's method will converge to one of the four roots.
• Which is converged to depends on the location of the initial guess.
• The following plot is colored as follows:
• Each point in the plane is a starting point for Newton's method applied to $x^4−1=0$.
• The color for each point depends on which solution the method converges to.
In [ ]:
n = 4000                   # number of points across plane
nit = 20                   # number of Newton iterations
x = np.linspace(-2,2,n)    # x points
y = np.linspace(-2,2,n)    # y points
X,Y = np.meshgrid(x,y)     # make 2-D array of x,y pts for plotting
Z = X + 1j*Y               # 2D array of initial guesses
for it in range(nit) :     # do Newton iterations (on the whole array at once)
Z = Z - (Z**4 - 1)/(4*Z**3)

plt.figure(figsize=(10,10))
phi = np.angle(Z)
plt.contourf(X,Y,phi,cmap='jet');

In [ ]: