Why do I get Index exceeds the number of array elements (1).

2 visualizaciones (últimos 30 días)
Maxim Baurov
Maxim Baurov el 1 de Jul. de 2020
Respondida: bharath pro el 2 de Jul. de 2020
Hello, this is my function
fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
x0 = 0.5;
A = [1;2];
b = [1;2];
[x,fval] = fmincon(fun,x0,A,b,[],[],[],[],[]);
when I try to run it I get an error, but i dont understand why

Respuestas (1)

bharath pro
bharath pro el 2 de Jul. de 2020
The error is caused because x0 is scaler but the function fun needs a vector ( x(1) and x(2) ). The following code works fine after I changed the dimensions of X0, A and B.
fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
x0 = [0.5,0.6];
A = [1,2];
b = 1;
[x,fval] = fmincon(fun,x0,A,b,[],[],[],[],[]);

Categorías

Más información sobre Nonlinear Optimization en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by