function newtonx3 % Roots of the equation x^3 - 1 = 0 r1 = 1.0; r2 = 0.5*(-1+i*sqrt(3)); r3 = 0.5*(-1-i*sqrt(3)); % Tolerance tol = 1.0E-08; re=linspace(-2,2,200); im=linspace(-2,2,200); [RE,IM]=meshgrid(re,im); C = zeros(size(RE)); for i1=1:size(RE,1), for i2=1:size(IM,2), r=newtonsolve(RE(i1,i2)+i*IM(i1,i2)); if abs(r-r1) < tol, C(i1,i2) = 1; end if abs(r-r2) < tol, C(i1,i2) = 2; end if abs(r-r3) < tol, C(i1,i2) = 3; end end end imagesc(re,im,C,[0,3]); colormap('jet(4)'); colorbar; hold on; plot(real(r1),imag(r1),'xk','LineWidth',2,'MarkerSize',10); plot(real(r2),imag(r2),'xk','LineWidth',2,'MarkerSize',10); plot(real(r3),imag(r3),'xk','LineWidth',2,'MarkerSize',10); hold off; xlabel('real'); ylabel('imag'); % solve equation x^3 - 1 = 0 using Newton's method function [x]=newtonsolve(x) N = 100; tol = 1.0E-10; for i=1:N, rk = x^3-1; if abs(rk)