In: Advanced Math
For the equation e^x =x+2,
(a) use the fixed point iteration method to determine its two roots
to eight correct decimal places (you may need to write this
equation in two different ways of x = g(x) in order to obtain these
two roots);
(b) numerically calculate the convergence rates for your converged
iterations; (c) compare these numerical convergence rates with the
theoretical conver- gence rates we presented in class (also see
Theorem 1.6 on page 38 of the textbook).
%%Matlab code for fixed point iteration
%function for fixed point iteration
clear all
close all
fprintf('\nFunction for which we have to find the root\n')
f1=@(x) exp(x)-(x+2);
disp(f1)
fprintf('\nFixed point iteration function \n')
f2=@(x) log(x+2);
disp(f2)
xx=0.3;%Initial guess
%loop for iterations
xx(1)=0.3;
c=1;
err=1;
%loop for fixed point iterations
while err>=10^-7
c=c+1;
xx(c)=double(f2(xx(c-1)));
err=abs(xx(c-1)-xx(c));
fprintf('\tRoot using fixed point method after
%d iteration is %f.\n',c-1,xx(c))
end
%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%%