Canuck - 5 months ago 30

Python Question

I am trying to add a constraint to a very complicated minimization problem I have but I am not sure how to implement it, even after reading the docs.

I have a simple example that if answered will help me with my original problem. Here is the code:

`from iminuit import Minuit`

def f(x,y,z):

return (x-1.)**2 +(y-2*x)**2 + (z-3.*x)**2 -1.

m=Minuit(f, x=.5, error_x=0.2, limit_x=(0.,1.), y=0.,limit_y=

(0.,1.), print_level=1)

m.migrad();

I would love to add a constraint, say x+y=1.

Thanks

Answer Source

Answer to my own question is don't bother using minuit. Use scipy.optimize with method SLSQP. It has equality and inequality constraint methods built in.