Question: Matlab code: I have given the Problem, Original Code and a partial answer to the problem. Please show all work and all steps for Problem

Matlab code: I have given the Problem, Original Code and a partial answer to the problem. Please show all work and all steps for Problem no#9. I would like the updated matlab code to fully run without errors to give me the answer.
Question no.9
Modify the user-defined function Bisection so that the table is not generated and the outputs are the approximate root and the number of iterations needed for convergence. All other parameters,including default values, are to remain unchanged. Save this function as Bisection_1.
Execute Bisection_1 to find the root of in the interval .
Partial Solution given:
>> f = @(x)(sin(x)+2*cos(x)-1);
>>[c,k]= Bisection_1(f,5,6)
c =5.6397
k =14
Orginal Code Given:
function c = Bisection(f, a, b, kmax, tol)
%
% Bisection uses the bisection method to approximate a root of f(x)=0
% in the interval [a,b].
%
% c = Bisection(f, a, b, kmax, tol), where
%
% f is an anonymous function representing f(x),
% a and b are the endpoints of interval [a,b],
% kmax is the maximum number of iterations (default 20),
% tol is the scalar tolerance for convergence (default 1e-4),
%
% c is the approximate root of f(x)=0.
%
if nargin <5|| isempty(tol), tol =1e-4; end
if nargin <4|| isempty(kmax), kmax =20; end
if f(a)*f(b)>0
c = 'failure';
return
end
disp(' k a b c (b-a)/2')
for k =1:kmax
c =(a+b)/2; % Find the first midpoint
if f(c)==0% Stop if a root has been found
return
end
fprintf('%3i %11.6f%11.6f%11.6f%11.6f
',k,a,b,c,(b-a)/2)
if (b-a)/2< tol % Stop if length of interval is within tolerance
return
end
if f(b)*f(c)>0% Check sign changes
b = c; % Adjust the endpoint of interval
else
a = c;
end
end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!