fsolve不适用于参数化函数句柄

时间:2016-05-28 17:39:48

标签: matlab solver numerical

例如,我定义了以下函数句柄:

F = @(x, y, z)[x+y+z; x*y*z];  
funcc = @(x, y)F(x, y, 0);  

电话

res = fsolve(funcc, [10; 10]);  

导致错误:

Error using @(x,y)F(x,y,0)
Not enough input arguments.

Error in fsolve (line 219)
        fuser = feval(funfcn{3},x,varargin{:});

Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.

我该如何解决?

1 个答案:

答案 0 :(得分:2)

请重新阅读requirements for the objective function in the documentation。该函数必须采用单个向量输入并返回向量。你试图传递两个标量。代替:

x0

目标函数的输入应符合您的初始猜测[10; 10]import std.stdio; import std.container.array; class RefType { } class MyContainer { private Array!RefType test; RefType result() const { // I want const on this, not on return type return test[0]; // use opIndex() from Array(T) // Error: cannot implicitly convert expression (this.test.opIndex(0u)) // of type const(RefType) to main.RefType } } int main(string[] argv) { auto c = new MyContainer; auto r = c.result(); return 0; } )。