![]() ![]() array ()) print ( f ( listxs )) print ( totsteps ) cnv, totsteps, listxs = NCG ( f, gradf, - 0.2777777, np. append ( xnext ) if ( maxiter = nsteps ): converge = "Not Converged" else : converge = "Converged" return ( converge, nsteps, xs ) cnv, totsteps, listxs = NCG ( f, gradf,. array (, 4 * x ])) def NCG ( f, gradf, alpha, x0, tol = 0.001, maxiter = 100 ): nsteps = 0 xs = xnext = x0 while ( nsteps tol ): xnext = xs + alpha * gradf ( xs ) nsteps = nsteps + 1 xs. Make a plot for theĬube roots of 1 - since there are 3 roots, there should be only 3ĭef f ( x ): return ( x ** 2 + 2 * x ** 2 ) def gradf ( x ): return ( np. The root that the starting point convered to. Has the same arguments, but this time the grid stores the identity of Plot_newton_basins(f, fprime, n=200, extent=, cmap='jet') Sure the axis ticks are correctly scaled. Finally plot the image using plt.imshow - make TheĪrgument cmap specifies the color map to use - the suggestedĭefaults are fine. ThereĪre n grid points in both the real and imaginary axes. Given by extent - for example, when extent = theĬorners of the plot are (-i, -i), (1, -i), (1, i), (-1, i). ![]() (or max_iter) for each point in a 2D array. Plot_newton_iters(f, fprime, n=200, extent=, cmap='hsv')Ĭalculates and stores the number of iterations taken for convergence To see some (pretty) aspects of Newton’s algorithm in the complex plane. Write the following two plotting functions F = lambda x : x ** 3 - 1 fprime = lambda x : 3 * x ** 2Įxercise 2 (20 points).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |