function F = Main(x) ↑ Error: Function definition not supported in this context. Create functions in code file.

function F = Main(x)
F(1) = x(1)^2 - 2 * x(2)^1 - 1;
F(2) = -3 * x(1)^2 + x(2)^2 + 2;
F(3) = x(1)^3 + x(2) ^ 3 - 2;
[x,fval] = fsolve(Main,[0, 0 , 0],options)
options=optimset('Display','iter')

回答 (2 件)

Zhonghua Sun
Zhonghua Sun 2019 年 12 月 21 日
From the above, it seems that the function of fsolve() is not defined before referenced.
function F = Main(x)
F(1) = x(1)^2 - 2 * x(2)^1 - 1;
F(2) = -3 * x(1)^2 + x(2)^2 + 2;
F(3) = x(1)^3 + x(2) ^ 3 - 2;
You need to store the above 4 lines in a file named Main.m
[x,fval] = fsolve(Main,[0, 0 , 0],options)
options=optimset('Display','iter')
You need to store the code
options = optimset('Display','iter');
[x,fval] = fsolve(Main,[0, 0 , 0],options)
in a different file, not named Main.m . Then you would execute that file.

カテゴリ

ヘルプ センター および File ExchangeGet Started with Optimization Toolbox についてさらに検索

質問済み:

2019 年 12 月 21 日

回答済み:

2019 年 12 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by