fmincon - Not Enough Input Arguments

Hello,
I am trying to run an optimization with fmincon, with the function defined independently.
x0 = [-1,2];
A = [1,2];
b = 1;
x = fmincon(z1_test,x0,A,b)
function f2 = z1_test(x)
100*(x(2)-x(1)^2)^2 + (1-x(1))^2
end
For whatever reason, I keep on getting the same error message.
Capture.PNG
But if I were to define the function thusly, I know it works
x0 = [-1,2];
A = [1,2];
b = 1;
z1_test = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
x = fmincon(z1_test,x0,A,b)
It is driving me crazy.

 Respuesta aceptada

madhan ravi
madhan ravi el 26 de En. de 2019
x0 = [-1,2];
A = [1,2];
b = 1;
x = fmincon(@z1_test,x0,A,b)
% ^------ missed it
function f2 = z1_test(x)
f2 = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
%^^--------- forgot to assign output
end

Más respuestas (0)

Categorías

Más información sobre Biotech and Pharmaceutical en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 26 de En. de 2019

Comentada:

el 26 de En. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by