Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help me check if it meets the grade criteras for problem number 2 which is included in the image. Below is the current code ,

Help me check if it meets the grade criteras for problem number 2 which is included in the image.
Below is the current code , if you try and write new code I will automatically downvote as this is being used to test if this is being checked by actual humans or chat GPT. Should it be found to be true I will be strongly considering cancelling my chegg subscription and upgrading to chat gpt 4.0 instead as I am highly annoyed there's no more humans on this website.
Code below:
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 consisting of real and imaginary components
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 Newton'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)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions