How to use a constraint on the output of a goal function?
6 次查看(过去 30 天)
显示 更早的评论
I have an optimization problem where I have 5 variables to optimize. I am using fmincon now wih sqp approach, but in future I may use some other methods as well. The issue is that for some specific combinations of my variables, the goal becomes a complex number, which is not desriable. I was wondering how to avoid these combinations.
For example, if F is my goal I want to set some check to see if F is a real number (and then accept it as a candidate). How can I do it? I have checked the documentation and I have just found setting up a constraint function that works as F <= 0, however I can't think of a clever way to tune this to my complex number problem.
0 个评论
采纳的回答
Torsten
2023-10-12
编辑:Torsten
2023-10-12
You must ask yourself: How could the objective function become complex-valued ? Maybe you have a log(x) expression in it and the x became negative ? Or you have an x^a expression in it and the x became negative ?
Once you found the reason, you might be able to set a constraint - either as a lower or upper bound on parameters or in the function "nonlcon" - to avoid this.
3 个评论
Torsten
2023-10-12
编辑:Torsten
2023-10-12
The first thing I would try is to define the product of the F_n as objective function.
The second thing I would try is to check in your objective function whether all F_n are > 0. If not, return -Inf or NaN (assuming you want to maximize).
The third thing I would try is to define F_n >= 0 for all n in "nonlcon" as constraints.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!