In: Advanced Math
2.5xˆ3=cos(x)+13.5 if your initail estimate is x0=1.1
%Matlab code for fixed point method
clear all
close all
%function for which root have to find using fixed point
method
f=@(x) 2.5*x.^3-cos(x)-13.5;
%displaying the function
fprintf('The function is \n')
disp(f)
%plotting the function
xx=linspace(1.1,3.5);
yy=f(xx);
plot(xx,yy)
xlabel('X')
ylabel('f(X)')
title('x vs. f(x) plot')
%function for fixed point iteration
g1=@(x) ((cos(x)+13.5)./2.5).^(1/3);
fprintf('Function for fixed point iteration \n')
disp(g1)
%initial guess
x0=1.1; err=1;k=0;
%loop for finding root using fixed point iteration
while err>10^-12
k=k+1;
x1=g1(x0);
err=abs(x0-x1);
x0=x1;
fprintf('\tAfter %d iteration the value x= %.15f
and error is %e.\n',k,x0,err)
end
fprintf('\nThe root for the function is %f.\n',x1)
hold on
plot(x1,f(x1),'r*')
%%%%%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%%%%%%