Question: Help me check if my code is correct based off the following criteria in the image: here's my code It has a error in regaurds

Help me check if my code is correct based off the following criteria in the image:
here's my code It has a error in regaurds to how it saves but it seems to meet criterias 1 and 3. "import numpy as np
import matplotlib.pyplot as plt
def nfractal(K, pixel, tol, n):
r =0.75 # ratio of number points along imaginary axis to number of points along real axis
a =1+0.5j
x_left =-1.5
x_right =1.5
y_bottom =-1.5
y_top =1.5
x = np.linspace(x_left, x_right, pixel) # x / real coordinates
y = np.linspace(y_bottom, y_top, round(pixel * r)) # y / imaginary coordinates
[Re, Im]= np.meshgrid(x, y) # meshgrid
Z = Re + Im *1.0j # matrix holding x and y coordinates or points on complex plane
B = np.zeros([round(r * pixel), pixel], float) # this matrix keeps track of speed of convergence to a root if B(i,j) is large, iteration converges...
Id = np.ones(B.shape) # matrix of ones
# roots of polynomial to apply Newton's iteration to, in this case p(z)= z^n -1
roots = np.exp(2j * np.pi * np.arange(n)/ n)
Zn = Z # initial guess for Newt
on's iteration
# iterate the initial guess Zn K times, the iteration is applied to the
# whole matrix using array element-by-element operations
for k in range(1, K):
Zn -= a *((Zn**n -1)/(n * Zn**(n -1)))
for i in range(n):
B +=(np.abs(Zn - roots[i]) tol)*(i +1)
# plot commands
plt.figure(figsize=(10,7.5))
plt.subplot(111)
plt.pcolormesh(x, y, B, cmap='rainbow', shading='auto')
plt.colorbar()
outfile = "plots/nfractal_summer2.png"
plt.savefig(outfile)
plt.show()
# Example usage:
nfractal(K=50, pixel=1000, tol=0.01, n=8)" Last thing to note is it outputs a graph successfully along with some errors but I am not sure if it meets criteria 2.
 Help me check if my code is correct based off the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!