Hello, I am getting an error like When trying to run this code Please help
function r = newton(fun,x0, xtol , ftol )23 % newton Newton's method to find a root of the scalar
4 % equation f (x) = 0
5 % Synopsis: r = newton(fun,x0, xtol , ftol )
6 % Input: fun = ( string ) name of mfile that
7 % returns f (x) and f '( x ).
8 % x0 = initial guess
9 % xtol = absolute tolerance on x.
10 % Smallest : xtol =5*eps
11 % ftol = absolute tolerance on f (x ).
12 % Smallest : ftol =5*eps
13 % Output: r = the root of the function
1415 xeps = max(xtol,5*eps);16 feps = max(ftol,5*eps); % Smallest tols are 5*eps
17 x = x0; k = 0;18 maxit = 15; % Initial guess, current and max iterations
19 while k ≤ maxit20 k = k + 1;21 % Returns f ( x(k−1) ) and f '( x(k−1) )
22 [f ,dfdx] = feval (fun,x);23 dx = f /dfdx;24 x = x − dx;25 if ( abs(f) < feps ), r = x; return; end26 if ( abs(dx) < xeps ), r = x; return; end27 end28 end2930 function [f , dfdx] = fx3n(x)31 % fx3n Evaluate f (x) = x − x ˆ(1/3) − 2 and
32 % dfdx for Newton algorithm
33 f = x − x .ˆ(1/3) − 2;34 dfdx = 1 −(1/3)*x .ˆ(−2/3);35 end
Best Answer