error message how to solve !?

조회 수: 3 (최근 30일)
Maisaa  Dabbah
Maisaa Dabbah 2021년 1월 19일
답변: Daniel Pollard 2021년 1월 19일
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

답변 (1개)

Daniel Pollard
Daniel Pollard 2021년 1월 19일
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.

카테고리

Help CenterFile Exchange에서 Data Exploration에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by