fmincon constraining some variables and not others
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I am trying to optimise a function depending on 6 optimisable variables using fmincon(). Some of the variables should be under inequality linear constrains, while others shouldn't have any constrain at all. Is there the possibility to enforce this with fmincon()?
I know that linear inequality constrains should be enforced by defining the system A · x ≤ b, but this forces me to impose a constrain over every element in x. Setting A(i,i) and b(i) as 0 seems a waste of CPU since fmincon() will probably keep using a constrain that actually is not.
One could think to define (A,b) and make their indices empty where no constrain should be, but of course this just concatenates A and b if they are vectors or is an error if A is a matrix.
Thank you for your answers.
0 comentarios
Respuesta aceptada
Matt J
el 1 de Dic. de 2020
Editada: Matt J
el 1 de Dic. de 2020
Setting A(i,i) and b(i) as 0 seems a waste of CPU since fmincon() will probably keep using a constrain that actually is not.
In theory, you can make A of type sparse, so that multiplications A(i,j)*x(j) for A(i,j)=0 will not be done explicitly. However, for such a small 6-variable problem, it doesn't make much sense. It is unlikely that these computations will consume noticeable additional CPU time.
Más respuestas (1)
Ameer Hamza
el 1 de Dic. de 2020
Editada: Ameer Hamza
el 1 de Dic. de 2020
"I know that linear inequality constrains should be enforced by defining the system A · x ≤ b, but this forces me to impose a constrain over every element in x. Setting A(i,i) and b(i) as 0 seems a waste of CPU since fmincon() will probably keep using a constrain that actually is not."
Why do you think so?
Conside the constraint
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/437548/image.png)
You will define it like this
A = [1 0 0 0 1 0];
B = 2;
This does not impose any constraint on x2, x3, x4, and x6.
3 comentarios
Matt J
el 1 de Dic. de 2020
Simple bounds like x1<=3, x5<=68 should not be expressed using the A,b matrices. You should use the lb, ub arguments for those. In any case, recent versions of Matlab will pre-analyze your A,b matrices to see if they contain any simple bounds and rewrite your constraints automatically.
Ver también
Categorías
Más información sobre Linear Least Squares en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!