The Bisection Method using MatLab The program hw2_bisec_inc.m has the structure
ID: 2966337 • Letter: T
Question
The Bisection Method using MatLab
The program hw2_bisec_inc.m has the structure and some parts of a program implementing the bisection method, but it is incomplete. Replace all the ?? with the appropriate entries and rename your program hw2_bisec.m. Verify that you program works by solving the following equations to the required accuracy. Write a different .m file for each function below and state explicitly what interval you are using to initiate the bisection method. (a) f (x) = sin x - cos x = 0 to within 10^-2. (b) f (x) = 5x^2 - 2e^x = 0 to within 10^-3. (c) f (x) = log x - x = 0 to within 10^-3.Explanation / Answer
a=input('enter the starting point of the interval ');
b=input('enter the ending point of the interval ');
err=input('enter the tolerance limit ');
f=input('enter the function ');
err1=1;
while err1>err
c=(a+b)/2;
fa=feval(f,a);
fb=feval(f,b);
fc=feval(f,c);
if fc>0
a=c;
else
b=c;
end
err1=abs(fc-0);
end
x=['the answer is ',num2str(c)];
disp(x)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.