我正在编写一个简单的函数来查找用户定义的方程的根。其职能如下:
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)我定义了函数'func‘及其导数'dfunc’如下
func=@(x) 2*x^2-3;dfunc=@(x) 4*x;
当尝试使用带有以下输入的函数时,它将返回以下错误消息
NR(func,dfunc,-1)未定义函数'NR‘,用于输入' function _handle’类型的参数。
我做错了什么?提前感谢您的帮助。
发布于 2013-10-08 22:22:04
确保matlab的工作目录/路径具有NR功能
如果不想这样,你可以
addpath('path_where_NR_is');https://stackoverflow.com/questions/19259497
复制相似问题