Clear Filters
Clear Filters

Example code for fmincon error.

1 view (last 30 days)
xinyu
xinyu on 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?

Accepted Answer

Shashank Prasanna
Shashank Prasanna on 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

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!