Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am working on the following Matlab Homework Problem and wanted to compare my answers. I have supplied the problem, Code used and the partial
I am working on the following Matlab Homework Problem and wanted to compare my answers. I have supplied the problem, Code used and the partial answer. Please show all work in matlab format.
Thanks
Modify the userdefined 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 Execute Bisection to find the root of in the interval
Partial Solution:
f @xsinxcosx;
ck Bisectionf
c
k
MatLab Code used:
function c Bisectionf a b kmax, tol
Bisection uses the bisection method to approximate a root of fx
in the interval ab
c Bisectionf a b kmax, tol where
f is an anonymous function representing fx
a and b are the endpoints of interval ab
kmax is the maximum number of iterations default
tol is the scalar tolerance for convergence default e
c is the approximate root of fx
if nargin isemptytol tol e; end
if nargin isemptykmax kmax ; end
if fafb
c 'failure';
return
end
disp k a b c ba
for k :kmax
c ab; Find the first midpoint
if fc Stop if a root has been found
return
end
fprintfi ffff
kabcba
if ba tol Stop if length of interval is within tolerance
return
end
if fbfc 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started