[英]Undefined function 'NR' for input arguments of type 'function_handle'. MATLAB
I'm writing a simple function to find the roots of a user defined equation. 我正在编写一个简单的函数来查找用户定义方程式的根。 The function is as follows: 功能如下:
function [root] = NR(func, dfunc, x_0)
x_r = x_0;
while func(x_r) > 10^-6
x_r = x_0 - func(x_0)/dfunc(x_0);
x_0 = x_r;
end
root = x_r;
fprintf('The root in the given interval is %.4f\n', root)
I defined my function 'func' and its derivative 'dfunc' as follows 我将函数“ func”及其派生的“ dfunc”定义如下
func=@(x) 2*x^2-3; func = @(x)2 * x ^ 2-3; dfunc=@(x) 4*x; dfunc = @(x)4 * x;
When attempting the use the function with the following input, it returns the following error messaage 尝试通过以下输入使用该功能时,它将返回以下错误消息
NR(func,dfunc,-1) Undefined function 'NR' for input arguments of type 'function_handle'. NR(func,dfunc,-1)类型为'function_handle'的输入参数的未定义函数'NR'。
What am I doing wrong? 我究竟做错了什么? Thanks in advance for any help. 在此先感谢您的帮助。
make sure you matlab's working directory/path has the NR function 确保您的matlab的工作目录/路径具有NR功能
if that's not desired, you can do 如果不需要的话,你可以做
addpath('path_where_NR_is');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.