我正在尝试将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;