FEVAL Error in Implementing Bisection - Function to evaluate must be represented as a string scalar, character vector, or function_handle object.

1 visualización (últimos 30 días)
Hello, I am getting an error like When trying to run this code Please help
function r = newton(fun,x0, xtol , ftol )
2
3 % 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
14
15 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 maxit
20 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; end
26 if ( abs(dx) < xeps ), r = x; return; end
27 end
28 end
29
30 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

Respuesta aceptada

Walter Roberson
Walter Roberson el 27 de Oct. de 2020
that code expects you to pass a function handle as the first parameter.

Más respuestas (0)

Categorías

Más información sobre Parallel Computing Fundamentals en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by