Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Matlab, programs may be written and saved in files with a suffix . m called M - files. There are two types of M
In Matlab, programs may be written and saved in files with a suffix m called Mfiles. There are two
types of Mfile programs: functions and scripts.
The following function program does iterations of the bisection method.
function mybisect
function mybisect
Does iterations of the bisection method for a function
Inputs : a function
left and right edges of the interval
the number of bisections to do
Outputs : the estimated solution of
e an upper bound on the error
evaluate at the ends and make sure there is a sign change
;
;
if
error Function has same sign at both endpoints.
end
disp:
for :
find the middle and evaluate there
;
;
disp
solved
;
;
break
jumps out the
decide which half
;
else
;
if solved the equation exactly
;
;
break
jumps out of the for loop end
decide which half to keep, so that the signs at the ends differ
if
;
else
;
end
end
set the best estimate for and the error bound
;
;
end
Your turn
Modify mybisect in above to create mybisectwhile to solve until the absolute error is bounded
by a given tolerance. Use a while loop to do this. Run your program on the function
with starting interval and a tolerance
How many steps does the program use to achieve this tolerance? You can count the
steps by adding to a counting variable in the loop of the program.
How big is the final residual
Turn in your program and a brief summary of the results.
The commands in the shell aremybisectwhilefabtol,n
Here is the sample function with "while" loop.
function mynewtontol tol
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