The minimized function value of f(x) should be greater than or equal to 0. However, scipy.optimize.minimize provides a negative value of f(x). Is there any way we could put a constraint on the function value?
Asked
Active
Viewed 114 times
-1

desertnaut
- 57,590
- 26
- 140
- 166

Thescott
- 1
-
1If your function can be negative, then I don't see why it's a problem that a *minimizer* finds a negative value. It's unclear why or what you want to constrain exactly: the function parameters, the function value (in which case: change the function to always return a positive value), or something else. Can you provide a (simplified) concrete example of your problem? – 9769953 Mar 15 '23 at 12:35
-
Please provide enough code so others can better understand or reproduce the problem. – Community Mar 16 '23 at 01:01
1 Answers
0
You could try to solve:
min z
z = f(x)
z >= 0
However, nonlinearly constrained problems are often more difficult to solve than unconstrained or linearly constrained problems.
If the model is essentially a root finding problem (i.e. we can get very close to zero), you can try:
min f(x)^2

Erwin Kalvelagen
- 15,677
- 2
- 14
- 39