The given equation has a root in the indicated interval.In MatLab, use the Bisection method to generate the first four midpoints and intervals (besides the original interval given) containing the root.
equation: e^x - 2x= 2,[0,2]
--------------------------------------------------------------------------------------------------------------------------------
code
-------------------------------------------------------------------------------------------------------------------------
clear all;
f=@(x) exp(x)-2*x-2;
a=0;
b=2;
fprintf('Given Interval %f %f\n',a,b);
j=0;
for i=1:4
c=(a+b)/2;
fprintf('For Interval-%d %f %f Mid Point is %f \n',j,a,b,c);
j=j+1;
if f(c)>0
b=c;
else a=c;
end
end
fprintf('Root of given equation is %f',c)
----------------------------------------------------------------------------
Output
------------------------------------------------------------------------------------------
Given Interval 0.000000 2.000000
For Interval-0 0.000000 2.000000 Mid Point is 1.000000
For Interval-1 1.000000 2.000000 Mid Point is 1.500000
For Interval-2 1.500000 2.000000 Mid Point is 1.750000
For Interval-3 1.500000 1.750000 Mid Point is 1.625000
Root of given equation is 1.625000>>
Get Answers For Free
Most questions answered within 1 hours.