When using Fmincon, how to avoid using "max", "if-else-end" in the constraints?
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Walter Roberson
on 28 Jan 2016
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 Comments
Walter Roberson
on 28 Jan 2016
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.
See Also
Categories
Find more on Nonlinear Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!