首页 > 解决方案 > 来自 fminunc 函数的未定义参数错误

问题描述

我正在尝试将 fminunc 与在外部文件中定义的函数一起使用。我正在研究的文档显示了一个带有内联函数定义的示例,并且它有效。我试图将该函数移动到另一个文件,但无法运行。有人可以告诉我我做错了什么吗?

>> inlinetest = @(x) x(1)^2 - 3*x(1);
>> fminunc(inlinetest, [5])
ans =  1.5000
>> mytest(5)
ans =  10
>> fminunc(mytest, [5])
error: 'x' undefined near line 2 column 7
error: called from
mytest at line 2 column 5
error: evaluating argument list element number 1
>>

#mytest.m contents
function r = mytest(x)
  r = x(1)^2 - 3*x(1);
endfunction;

标签: octave

解决方案


推荐阅读