Question
function [x,y,n]=secantf(fn,xl,xu,tol,max) % Function to find the root of a function fn using the Secant method %Inputs are:- % fn = funtion name in quotes
function [x,y,n]=secantf(fn,xl,xu,tol,max)
% Function to find the root of a function fn using the Secant method
%Inputs are:-
% fn = funtion name in quotes
% xl, xu = lower and upper guesses of the root
% tol = tolerance level
% max = maximum number of iterations allowed
%Outputs are:-
% x => desired root
% y => error in calculating root
% n => number of iterations
n=0;
error=1;
errora=1000;x=1000;
while errora > tol
fl=feval(fn,xl);
fu=feval(fn,xu);
xr=xl-fl*(xu-xl)/(fu-fl);
fr=feval(fn,xr);
xold=x;
x=xr;y=fr;
xl=xu;xu=xr;
errora=abs((x-xold)/(x+1e-20)*100);
error=abs(y);
n=n+1;
if n >= max
disp('Warning! Maximun number of iterations reached but not converged yet!')
break
end
end
Please help me write the matlab code to answer this question using the secant method.
Required information Consider the function Determine the positive root of the given function using the secant method (three iterations, x-1 = 0.5 and x0-04). (Round the final answer to four decimal places.) The positive root after three iterations isStep 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