Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB 1. Find all the roots in [-5,5] of f(x) = cos x + 1/x^3 + 200 using the b

ID: 2902626 • Letter: M

Question

MATLAB

1. Find all the roots in [-5,5] of f(x) = cos x + 1/x^3 + 200 using the bisection algorithm in MATLAB with a tolerance of 10^-10. Plot the function first to see how many roots there are, then run the algorithm the indicated number of times to get the roots one at a time. Turn in a code listing and the answers, printed with at least 8 significant digits. Also report the number of iterations it took to find each root. 2. Use the fixed point algorithm to find the fixed point of x =1/x (sin x +1(cos x - 1)) Use MATLAB to find the fixed point, which happens to lie in the interval [0, 0.5]. You do not need to verify that fact. Use a tolerance of 10^-10. Turn in the code listing and the solution, printed with at least 8 significant digits.

Explanation / Answer

clear all
clc

format long
eps_abs = 1e-10;
eps_step = 1e-10;
a = -5.0;
b = 5.0;
f=@(x) cos(x)+(1/(x^3+200));
format long
fplot(f,[-5 5])

% from the plot,we see there are 4 roots

root1=zeros(1,4); % to store the roots to compare each time we get a root
count=0; % to keep count of roots found
while (b - a >= eps_step || ( abs( f(a) ) >= eps_abs && abs( f(b) ) >= eps_abs ) )
c = (a + b)/2;
if ( f(c) == 0 )
break;
elseif ( f(a)*f(c) < 0 )
b = c;
else
a = c;
end
end
x=['root is ',num2str(c)];
disp(x)