% Runs Newton\'s method to find roots of f(z) . It col function [a,n,TOL,N]=P3(a,n,TOL,N) A=zeros(n,n,\'uint8\'); f = inline(\'z^3-1\'); % Define f and f\'. fprime = inline(\'3*z^2\'); rts=roots([1 0 0 -1]) h=2*a/n; for j=1:n+1, % Try initial values with imaginary parts between y = -a + (j-1)*h; % -a and a for i=1:n+1, % and with real parts between x = -a + (i-1)*h; % -a and a. z = x + 1i*y; zk = z; kount = 0; % kount is the total number of iterations. conv1 = 0; % conv1,2,3 count iterations when approx soln is within conv2 = 0; % TOL of root1,2,3. conv3 = 0; while kount < 40 & conv1 < 5 & conv2 < 5 & conv3 < 5, kount = kount + 1; zk = zk - f(zk)/fprime(zk); % This is the Newton step. if abs(zk-root1) < TOL, % Check for convergence to root1. conv1 = conv1 + 1; else conv1 = 0; end; if abs(zk-root2) < TOL, % Check for convergence to root2. conv2 = conv2 + 1; else conv2 = 0; end; if abs(zk-root3) < TOL, % Check for convergence to root3. conv3 = conv3 + 1; else conv3 = 0; end; end; if conv1 >=3, M(j,i,1) = 255; end; % Converged to root 1. Color point green. if conv2 >=3, M(j,i,2) = 255; end; % Converged to root 2. Color point red. if conv3 >=3, M(j,i,3) = 255; end; % Converged to root 3. Color point blue. end; end; imshow(A) Solution % Runs Newton\'s method to find roots of f(z) . It col function [a,n,TOL,N]=P3(a,n,TOL,N) A=zeros(n,n,\'uint8\'); f = inline(\'z^3-1\'); % Define f and f\'. fprime = inline(\'3*z^2\'); rts=roots([1 0 0 -1]) h=2*a/n; for j=1:n+1, % Try initial values with imaginary parts between y = -a + (j-1)*h; % -a and a for i=1:n+1, % and with real parts between x = -a + (i-1)*h; % -a and a. z = x + 1i*y; zk = z; kount = 0; % kount is the total number of iterations. conv1 = 0; % conv1,2,3 count iterations when approx soln is within conv2 = 0; % TOL of root1,2,3. conv3 = 0; while kount < 40 & conv1 < 5 & conv2 < 5 & conv3 < 5, kount = kount + 1; zk = zk - f(zk)/fprime(zk); % This is the Newton step. if abs(zk-root1) < TOL, % Check for convergence to root1. conv1 = conv1 + 1; else conv1 = 0; end; if abs(zk-root2) < TOL, % Check for convergence to root2. conv2 = conv2 + 1; else conv2 = 0; end; if abs(zk-root3) < TOL, % Check for convergence to root3. conv3 = conv3 + 1; else conv3 = 0; end; end; if conv1 >=3, M(j,i,1) = 255; end; % Converged to root 1. Color point green. if conv2 >=3, M(j,i,2) = 255; end; % Converged to root 2. Color point red. if conv3 >=3, M(j,i,3) = 255; end; % Converged to root 3. Color point blue. end; end; imshow(A).