Filter löschen
Filter löschen

Example code for fmincon error.

1 Ansicht (letzte 30 Tage)
xinyu
xinyu am 23 Feb. 2013
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?

Akzeptierte Antwort

Shashank Prasanna
Shashank Prasanna am 23 Feb. 2013
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 Kommentar
xinyu
xinyu am 23 Feb. 2013
That's correct. Thank you very much.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by