フィルターのクリア

Example code for fmincon error.

1 回表示 (過去 30 日間)
xinyu
xinyu 2013 年 2 月 23 日
Hello, everyone. I was tryint to get the idea of using the function fmincon earlier. But when I run the example code in the hlep document, it seems that it doesn't work. the code:
function f = myfun(x)
f = -x(1) * x(2) * x(3);
= [-1 -2 -2; ...
1 2 2];
b = [0;72];
x0 = [10;10;10]; % Starting guess at the solution
[x,fval] = fmincon(@myfun,x0,A,b);
According to the hlep, a solution to the optimize problem should be given. But when I copied the code into a new script and run it, I got the error:
>> myfun
Error using myfun (line 2)
Not enough input arguments.
what does this means here, can anybody please explain this to me?

採用された回答

Shashank Prasanna
Shashank Prasanna 2013 年 2 月 23 日
is you objective function, you shouldn't run that. Create the definition of myfun into a separate file called myfun.m:
function f = myfun(x)
f = -x(1) * x(2) * x(3);
= [-1 -2 -2; ...
1 2 2];
And the rest of the code into a different script for example run_fmincon.m:
b = [0;72];
x0 = [10;10;10]; % Starting guess at the solution
[x,fval] = fmincon(@myfun,x0,A,b);
>> run_fmincon
  1 件のコメント
xinyu
xinyu 2013 年 2 月 23 日
That's correct. Thank you very much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver 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