error message how to solve !?

3 views (last 30 days)
Maisaa  Dabbah
Maisaa Dabbah on 19 Jan 2021
Answered: Daniel Pollard on 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

Answers (1)

Daniel Pollard
Daniel Pollard on 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.

Categories

Find more on Data Exploration in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!