II. Consider the task of numerically approximating the solution of the equation
ID: 3209762 • Letter: I
Question
II. Consider the task of numerically approximating the solution of the equation x3 + x + 1 = 0 for x E [-1,0] within 10-5 and with 100 maximum iterations. 1. Compute a sequence of iterates (n)nzi using: (a.) Newton's Method with zo--1, (b.) the Bisection Method and (c.) the fixed point iteration method with r2 +1 You donot have to turn in the MATLAB program but you do need to report your computed output in the following form for each of the methods: nIf()-a-order Note - Perform all your calculations in the format long setting in MATLAB. -The true root can be obtained by calling the MATLAB function fzero. For more details, type help fzero in the MATLAB command window. The order of the convergence can be obtained in the following manner: order ~-log 11 log refers to the natural log.Explanation / Answer
1)
a.)Newton Method:
clc;clear all;close all;
x(1)=-1;
f=@(x) ((x.^3)+x+1);
g=@(x) ((3.*(x.^2))+1);
for i=1:10
x(i+1)=x(i)-((f(x(i)))/(g(x(i))));
end
third=f(x);
ans=fzero(f,x(1));
display(ans);
for i=2:10
fourth(i)=abs(x(i)-x(i-1));
fifth(i)=abs(ans-x(i-1));
end
for i=3:10
order(i)=log(abs((x(i+1)-x(i))/(x(i)-x(i-1))))/log(abs((x(i)-x(i-1))/(x(i-1)-x(i-2))));
end
Results:
b)Bisection method:
clc;clear all;close all;
a=-1;b=0;
x(1)=a;y(1)=b;
z(1)=(a+b)/2;
f=@(x) ((x.^3)+x+1);
for i=1:100
z(i)=(x(i)+y(i))./2;
if (f(x(i))*f(z(i)))<0
x(i+1)=x(i);y(i+1)=z(i);
else
x(i+1)=z(i);y(i+1)=y(i);
end
end
third=f(z);
ans=fzero(f,z(1));
display(ans);
for i=2:100
fourth(i)=abs(x(i)-x(i-1));
fifth(i)=abs(ans-x(i-1));
end
for i=3:100
order(i)=log(abs((x(i+1)-x(i))/(x(i)-x(i-1))))/log(abs((x(i)-x(i-1))/(x(i-1)-x(i-2))));
end
Result:
c)Fixed-Point iteration method:
clc;clear all;close all;
x(1)=-1;
for n=1:100
x(n+1)=((-1)/(((x(n)).^2)+1));
end
f= @(x) ((x.^3)+x+1);
ans=fzero(f,x(1));
display(ans);
third=f(x);
for i=2:100
fourth(i)=abs(x(i)-x(i-1));
fifth(i)=abs(ans-x(i-1));
end
for i=3:100
order(i)=log(abs((x(i+1)-x(i))/(x(i)-x(i-1))))/log(abs((x(i)-x(i-1))/(x(i-1)-x(i-2))));
end
Result:
Note: All results were pasted from the MATLAB outputs of the codes given, and are upto iterations of given accuracy (0.00001), though 100 iterations were initially made for accuracy of answer, for each process the required iterations for such accuracy were actually very less in comparision to 100, and those number of iterations can be seen in the results.
n xn f(xn) |xn-xn-1| |sol-xn-1| order 0 -1 -1 0 0 1 -0.75 -0.17188 0.25 0.317672 0 2 -0.68605 -0.00894 0.063953 0.067672 0 3 -0.68234 -2.82E-05 0.003707 0.003719 2.089006 4 -0.68233 -2.84E-10 1.18E-05 1.18E-05 2.019581 5 -0.68233 0 1.18E-10 1.18E-10 2.000626 6 -0.68233 0 0 0 Inf