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 日

0 投票

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 件のコメント

Khoirunnisa' Irodatillah
Khoirunnisa' Irodatillah 2019 年 3 月 27 日
Thank you, it works. Why is my function doesn't work? The answer would be really helpful when I get the same problem next time..
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 件)

カテゴリ

ヘルプ センター および File Exchange で Get Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by