Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions