%script file to make a movie of newton iteration function plots %varying with a parameter %create real and imaginary value arrays [X,Y]=meshgrid([-2:0.01:2]); [m,n]=size(X); maxiters=30; %parameters for the function C(z)=z^3+a*z+b a=0; %vary real part of b br=-1:0.1:1; for q=1:length(br) b=br(q)+0*i; %numerical values for the roots(must be calculated each time) p=[1 0 a b]; rts=roots(p); r1=rts(1); r2=rts(2); r3=rts(3); T=64*ones(m,n); for j=1:m fprintf ('on iterate %d\n',j); for k=1:n z=X(j,k)+i*Y(j,k); for t=1:maxiters y=z-(z^3+a*z+b)/(3*z^2+a); z=y; if abs(z-r1)<.001 T(j,k)=1+t*(20/maxiters); break; end if abs(z-r2)<.001 T(j,k)=30+t*(20/maxiters); break; end if abs(z-r3)<.001 T(j,k)=45+t*(20/maxiters); break; end end end end image(T); %save picture as movie frame M(:,q)=getframe; end movie(M,3);