Not Enough Input Arguments in fsolve

1 次查看(过去 30 天)
please help to solve and explain why
function f = fun(x)
f(1) = (x(1)-4)^2 +(x(2)-4)^2 - 5;
f(2) = x(1)^2 + x(2)^2 - 16;
options = optimset('display','off')
x = fsolve(@fun,[2 3.5],options)
X = x(1)
Y = x(2)
>> fun()
Not enough input arguments.
Error in fun (line 2)
f(1) = (x(1)-4)^2 +(x(2)-4)^2 - 5;
>>

采纳的回答

Catalytic
Catalytic 2019-3-27
编辑:Catalytic 2019-3-27
function myProblem
options = optimset('display','off')
x = fsolve(@fun,[2 3.5],options)
X = x(1)
Y = x(2)
function f = fun(x)
f(1) = (x(1)-4)^2 +(x(2)-4)^2 - 5;
f(2) = x(1)^2 + x(2)^2 - 16;
end
end
Running gives the following result
>> myProblem
x =
1.8058 3.5692
X =
1.8058
Y =
3.5692
  3 个评论
Catalytic
Catalytic 2019-3-27
As you can now see, fun() is supposed to contain only the code that computes f.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by