fmincon constraining some variables and not others
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Matt J
2020-12-1
编辑:Matt J
2020-12-1
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.
更多回答(1 个)
Ameer Hamza
2020-12-1
编辑:Ameer Hamza
2020-12-1
"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
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 个评论
Matt J
2020-12-1
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Least Squares 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!