Write an M-file to solve an equation with the bisection method and with the seca
ID: 2997237 • Letter: W
Question
Write an M-file to solve an equation with the bisection method and with the secant method to a desired accuracy precision.
Request upper and lower limits for bisection (you may assign a step size or request an input value)
Request the first guess value and precision desired for the secant method.
Create a sub-function to calculate the function value.
Create a sub-function to calculate the slope/secant value.
(You may create functions for the two methods if you desire but it is not required for your grade)
Name the file (and function) using your username and submit to this assignment to WebHW under assn3.
Remember - comments are important.
I just dont know how to creat a bisection method and secant method function.
Explanation / Answer
function [x e] = mybisect(f,a,b,n)
% function [x e] = mybisect(f,a,b,n)
% Does n iterations of the bisection method for a function f
% Inputs: f -- an inline function
% a,b -- left and right edges of the interval
% n -- the number of bisections to do.
% Outputs: x -- the estimated solution of f(x) = 0
% e -- an upper bound on the error
format long
format compact
c = f(a); d = f(b);
if c*d > 0.0
error(
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.