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
![function [x,y,n]=secantf(fn,xl,xu,tol,max) % Function to find the root of a function fn](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3927f28b2c_78266f3927ebfa48.jpg)
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 is
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
