Use the Bisection method to find the roots of fx 2x x cosx
Solution
(1)
function f=myeq(a,b)
x=a:0.01:b;
f=(2./x-x).*cos(x)-1;
end
--------------------brackplot.m------------
clc;
clear all;
close all;
a=0.5;
b=5;
f=myeq(a,b);
plot(f)
(2)
clc;
clear all;
close all;
x1=0.5;
x2=5;
y1=(2/x1 -x1)*cos(x1)-1;
if(y1<0)
x1=x1;
x2=x2;
else
x=x2;
x2=x1;
x1=x;
end
n=100;
i=1;
while(n>0)
y1=(2/x1-x1)*cos(x1)-1;
y2=(2/x2-x2)*cos(x2)-1;
y=y1*y2;
if (y<0)
x=(x1+x2)/2
y=(2/x-x)*cos(x)-1;
if(y<0)
x1=x;
else
x2=x;
end
end
tol(i)=abs(y);
if(tol(i)<(0.01))
n=-1;
end
i=i+1;
n=n-1;
end
fprintf(\'Rooots of given problem by using Bi-Section Method : %d and %d(Iterations)\ \',x,i-1);
OUTPUT:
x =
2.7500
x =
3.8750
x =
4.4375
x =
4.7188
x =
4.5781
x =
4.5078
x =
4.4727
x =
4.4551
x =
4.4639
x =
4.4595
Rooots of given problem by using Bi-Section Method : 4.459473e+00 and 10(Iterations)
>>
![Use the Bisection method to find the roots of f(x) = (2/x - x) cosx - 1 on the interval [0.5, 5]. First write the function f(x) as myeq.m in MATLAB; use the br Use the Bisection method to find the roots of f(x) = (2/x - x) cosx - 1 on the interval [0.5, 5]. First write the function f(x) as myeq.m in MATLAB; use the br](/WebImages/4/use-the-bisection-method-to-find-the-roots-of-fx-2x-x-cosx-978691-1761502238-0.webp)
![Use the Bisection method to find the roots of f(x) = (2/x - x) cosx - 1 on the interval [0.5, 5]. First write the function f(x) as myeq.m in MATLAB; use the br Use the Bisection method to find the roots of f(x) = (2/x - x) cosx - 1 on the interval [0.5, 5]. First write the function f(x) as myeq.m in MATLAB; use the br](/WebImages/4/use-the-bisection-method-to-find-the-roots-of-fx-2x-x-cosx-978691-1761502238-1.webp)
![Use the Bisection method to find the roots of f(x) = (2/x - x) cosx - 1 on the interval [0.5, 5]. First write the function f(x) as myeq.m in MATLAB; use the br Use the Bisection method to find the roots of f(x) = (2/x - x) cosx - 1 on the interval [0.5, 5]. First write the function f(x) as myeq.m in MATLAB; use the br](/WebImages/4/use-the-bisection-method-to-find-the-roots-of-fx-2x-x-cosx-978691-1761502238-2.webp)