When using Fmincon, how to avoid using "max", "if-else-end" in the constraints?
2 次查看(过去 30 天)
显示 更早的评论
I have some functions which will be called by the constraints, for example:
mx = 1.4 - 1.1*10^(-4)*Jz - 0.2*10^(-8)*Jz^2;
It could be that Jz is quite big and mx will be smaller than 0. Is that OK to modify this function like below ?
mx = max(1.4 - 1.1*10^(-4)*Jz - 0.2*10^(-8)*Jz^2, 0);
Will Fmincon like this? If not, how to avoid it? Thank you!
0 个评论
回答(1 个)
Walter Roberson
2016-1-28
If Jz is one of the inputs, then split the task into three pieces,
Jz < -27500-2500*sqrt(233)
Jz > -27500+2500*sqrt(233)
-27500-2500*sqrt(233) <= Jz <= -27500+2500*sqrt(233)
In the first two cases, the constraint function should hard-code mz as 0; in the third case, use your current calculation. Run all three cases, and take the best of the results.
3 个评论
Walter Roberson
2016-1-28
I was asking if Jz is one of the variables being optimized.
Is it possible to place a linear constraint on the variables being optimized, so that Jz will not exceed the range I indicated?
Yes, I did mean run the three cases independently using fmincon()
Using min() or max() or if/else in a nonlinear constraint is not always a problem. However, when the boundary cannot be expressed as a linear combination of the variables being optimized, you run the risk that you are breaking up the input space into non-continguous regions, and if that happens then fmincon's algorithms will fail. If the nonlinear constraints are acting to create a dividing hyperplane that is just difficult to express linearly, then you are probably okay.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!