In: Advanced Math
Apply Newton’s method and the modified method to the equation f(x) = 1−cos(x−5) to approximate the a double root 5. Compare the results and demonstrate the superiority of the modified method. Numerically identify the rates of convergence of both the methods.
The iterative scheme for the Newton Raphson method is given below :
provided
The code for Newton Raphson method is attached below.
%Newton Raphson Method%%%%%%%%%%%%%%%%%%
clear all;
syms x;
f=1-cos(x-5); %Enter the Function here
g=diff(f); %The Derivative of the Function
n=input('Enter the number of decimal places:');
epsilon = 5*10^-(n+1);
x0 = input('Enter the intial approximation:');
for i=1:100
f0=vpa(subs(f,x,x0)); %Calculating the value of function at
x0
f0_der=vpa(subs(g,x,x0)); %Calculating the value of function
derivative at x0
y=x0-f0/f0_der; % The Formula
err=abs(y-x0);
if err<epsilon %checking the amount of error at each
iteration
break
end
x0=y;
end
y = y - rem(y,10^-n); %Displaying upto required decimal
places
fprintf('The Root is : %f \n',y);
fprintf('No. of Iterations : %d\n',i);
Output
Enter the number of decimal places:5
Enter the intial approximation:4.5
The Root is : 4.999990
No. of Iterations : 17
The iterative scheme for Modified Newton method is
where
The code for the Modified Newton scheme is attached below.
%%Modified Newton method%%%%%%%%
clear all;
syms x;
f=1-cos(x-5); %Enter the Function here
g=diff(f); %The Derivative of the Function
u=f/g;
v=diff(u);
n=input('Enter the number of decimal places:');
epsilon = 5*10^-(n+1);
x0 = input('Enter the intial approximation:');
for i=1:100
f0=vpa(subs(f,x,x0)); %Calculating the value of function at
x0
f0_der=vpa(subs(g,x,x0)); %Calculating the value of function
derivative at x0
u0=vpa(subs(u,x,x0));
u0_der=vpa(subs(v,x,x0));
y=x0-u0/u0_der; % The Formula
err=abs(y-x0);
if err<epsilon %checking the amount of error at each
iteration
break
end
x0=y;
end
y = y - rem(y,10^-n); %Displaying upto required decimal
places
fprintf('The Root is : %f \n',y);
fprintf('No. of Iterations : %d\n',i);
Output
modifiednewton_raphson
Enter the number of decimal places:5
Enter the intial approximation:4.5
The Root is : 4.999990
No. of Iterations : 3
Comparison and Superiority
Comparing the both methods, we can see the number of iteration for Modified Newton Scheme is 3 which is less than the number of iteration for Newton Raphson scheme ,17.
Rate of Convergence
For the rate of convergence, I am hereby attaching an image file below.