function newton_v_fixedpoint; % p is the approximatoin of newtons's method % q is the approximation of fixed point method p=1; q=1; % n is the number of iterations n=6; % the same loop is for the both methods fprintf(1, '\n \n Compare the two methods \n'); for i=1:1:20 p=p-f(p)/der_f(p); q=g(q); fprintf(1,'Iteration: %3i Newton`s: %12.10f Fixed point: %12.10f \n', i,p,q); end function y=g(x); % use example 2.2#7, solve as fixed point problem %y=pi+0.5*sin(x/2); y=-x^2+x; % function y=f(x); % use example 2.2#7 solve as root finding problem by Newton's method %y=pi+0.5*sin(x/2)-x; %y=x^2; y=(abs(x))^(2/3); function y=der_f(x); % use example 2.2#7 solve as root finding problem by Newton's method %y=cos(x/2)/4-1; %y=2*x; y=sign(x)*(abs(x))^(-1/3)*2/3;