Borrar filtros
Borrar filtros

Example code for fmincon error.

1 visualización (últimos 30 días)
xinyu
xinyu el 23 de Feb. de 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?

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by