clc clear all close all % Coding the Newton Fractal | Lecture 19 | Numerical Methods for Engineers % Jeffery Chasnov RU-vid % Goal: Iterate Newton's Method %BIG IDEA: The given function, z(x)=x^3-1, has 3 roots in the complex plane. 1st, we take all %the pixels (points) in a grid and we run the Newton-Raphson equation on it a # of times. %Once we are certain as to which root the point is converging, we label that point with a # : %1,2,3, or 0 which corresponds to the color of that pixel being red, green ,blue, or black %respectively. %find the zeros of f(z)=z^3-1 %iterate the grid points z_+n+1=z_n-f(z_n)/f'(z_n) f=@(z)z.^3-1;fp=@(z)3*z.^2; root1=1;root2=-1/2+1i*sqrt(3)/2;root3=-1/2-1i*sqrt(3)/2;%the 3 roots of f(z) are the cube roots of unity nx=100; ny=100; xmin=-2;xmax=2; ymin=-2;ymax=2; x=linspace(xmin,xmax,nx); y=linspace(ymin,ymax,ny); [X,Y]=meshgrid(x,y); z=X+1i*Y; nit=40;%notice use of break points (red highlihgted nunmber lines) for n=1:nit z=z-f(z)./fp(z); end %Setting up grid: %determing which root the grid point converges to (the closest root) eps=.001; z1=abs(z-root1)
@@ProfJeffreyChasnov Hi Jeffrey! First of all, thank you for this amazing series. Dark mode is just so that the computer screen background meanwhile you code is black, thus, making it less eye-tiring to see the screen while you code; since its generally a time consuming action.