error message how to solve !?

2 vues (au cours des 30 derniers jours)
Maisaa  Dabbah
Maisaa Dabbah le 19 Jan 2021
hey
i keep getting this error:
"Undefined function 'NR' for input
arguments of type 'function_handle'."
the NR function is a function that i built in order to apply the newton raphson method.
this is the function code :
function [res,k]=NR(x0,tol,f,f_prime,max_iter)
X_k=x0;
X_k_val=f(x0);
i=2;
while abs(X_k_val(i-1))>tol && i<max_iter
X_k(i)= X_k(i-1) - f(X_k(i-1)) / f_prime(X_k(i-1));
X_k_val(i)=f(X_k(i));
i=i+1;
end
our_sol = X_k(length(X_k));
res=table([1:i-1]',X_k',X_k_val',abs(X_k - our_sol)','VariableNames',{'Iteration','X','f_X','|X_k - x*|'});
k = 1:i-1;
%iter_val = f(X_k(k));
end

Réponses (1)

Daniel Pollard
Daniel Pollard le 19 Jan 2021
The error message is exactly what it says. You defined a function, which is not defined if one of your inputs is a function handle.
To pass a function into another function, use the @ notation.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by