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

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!