Not Enough Input Arguments in fsolve

조회 수: 1 (최근 30일)
Khoirunnisa' Irodatillah
Khoirunnisa' Irodatillah 2019년 3월 27일
댓글: Khoirunnisa' Irodatillah 2019년 3월 27일
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.
Khoirunnisa' Irodatillah
Khoirunnisa' Irodatillah 2019년 3월 27일
OH.. I see,, thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (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