简体   繁体   English

类型为“ function_handle”的输入参数的未定义函数“ NR”。 MATLAB

[英]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.

相关问题 在 Matlab 中使用 fzero 时出错:未定义 function 或输入 arguments 类型为“function_handle”的方法“det” - Error using fzero in Matlab: Undefined function or method 'det' for input arguments of type 'function_handle' 在MATLAB中获得function_handle的派生 - Get the derivative of a function_handle in MATLAB Matlab错误:未定义的函数'knnclassify'用于'double'类型的输入参数 - Matlab Error: Undefined function 'knnclassify' for input arguments of type 'double' 错误-Matlab中类型为'double'的输入参数的未定义函数'imbinarize' - Error - Undefined function 'imbinarize' for input arguments of type 'double' in matlab MATLAB:??? 类型为'char'的输入参数的未定义函数或方法'sprint' - MATLAB: ??? Undefined function or method 'sprint' for input arguments of type 'char' 类型为“ sym”的输入参数的未定义函数“ sparse”。 (Matlab的) - Undefined function 'sparse' for input arguments of type 'sym'. (Matlab) MATLAB:类型为'char'的输入参数的未定义函数'string'吗? - MATLAB: Undefined function 'string' for input arguments of type 'char'? Matlab:类型为“ cell”的输入参数的未定义函数“ graph” - Matlab: Undefined function 'graph' for input arguments of type 'cell' Matlab错误:类型为'uint8'的输入参数未定义函数'svd' - Matlab error: Undefined function 'svd' for input arguments of type 'uint8' Matlab:类型为“ cell”的输入参数的未定义函数“ eq” - Matlab: Undefined function 'eq' for input arguments of type 'cell'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM