Source Code Problem 1 Write separate MATLAB functions for Ne
Source Code Problem 1: Write separate MATLAB functions for Newton\'s, the Secant method, the modified secant method. The functions should be written so that they can be called in MATLAB by typing 1. [X, Numlters]=Newton(@f, @df, x0, TOL, Max Iters) 2. [X, Numlters-Secant(af, x0, x1, TOL, Maxlters) 3. [(X, Nunn lters)-ModifiedSecant(@f, , x0,TOL, Maxlters)
Solution
1.[X,Numilters]=(newton@f,@df,x0,tol,maxlter)
2.[X.Numlters]=secant(@f,x0,x1,tol,maxlters):
function [x, xi, iter] = secant( f, x0, x1, nmax, tol )
x = root of f
xi = vector containing each approximation to x at each iteration
iter = number of iterations used to find root
f = function handle for function f
x0, x1 = initial values for the secant method
nmax = max. number of iterational
tol = degree of accuracy (\'within error of tol\')
xi(0) = x0;
xi(1) = x1;
k = 1;
while tol < error
while (k-1) < nmax
xi(k+1) = xi(k) - (xi(k) - xi(k-1))/(f(xi(k)) - f(xi(k-1)));
error = ;
k = k+1;
end
end
x = xi(k)
xi
iter = k
end
