% routine to create a Newton's method plot n = 81; % an odd number prevents a zero n = input('enter resolution ->'); dx = 3/n; nits = 10; % number of full matrix iterations tol = 0.25; % how close we need to be a root to % declare convergence % w1, w2, w3 are the roots of the equation x^3-1=0 w1 = 1; w2 = exp(2*pi*i/3); w3 = w2*w2; disp('Generating base matrix'); [X,Y] = meshgrid(-1.5:dx:1.5); m = X + i*Y; disp(size(m)); clear X,Y; disp(['Base matrix of size ',int2str(prod(size(m))),' created']); disp(['Doing ',int2str(nits),' full matrix steps']); % first round of calculations % we compute the newton iteration for % all entries of the matrix for k=1:nits m = m - (m.^3-1)./(3*m.^2); disp(['Step #',int2str(k),' finished']); end; % mm records which root we're nearest mm = 1*(abs(m-w1)