# How to find local minima of multi-parameter function?

With sage, I can use find_local_minimum to find local minima of a function over one variable.

What's a corresponding function for multi-variable functions?

edit retag close merge delete

Sort by » oldest newest most voted

The simplest is probably to use scipy.optimize.minimize

sage: import scipy.optimize
sage: def f(X):
....:     x,y = X
....:     return 3*x^2 + 2*y^2 + x + y*cos(x*y)
sage: res = scipy.optimize.minimize(f,(0,0))
sage: res.x
array([-0.16623723, -0.2493558 ])

more

In SageMath, you have minimize :

  sage: vars = var('x y z')
sage: f = 100*(y-x^2)^2+(1-x)^2+100*(z-y^2)^2+(1-y)^2
sage: minimize(f, [.1,.3,.4]) # abs tol 1e-6
(1.0, 1.0, 1.0)


and minimize_constrained :

  sage: y = var('y')
sage: f = lambda p: -p[0]-p[1]+50
sage: c_1 = lambda p: p[0]-45
sage: c_2 = lambda p: p[1]-5
sage: c_3 = lambda p: -50*p[0]-24*p[1]+2400
sage: c_4 = lambda p: -30*p[0]-33*p[1]+2100
sage: a = minimize_constrained(f,[c_1,c_2,c_3,c_4],[2,3])
sage: a
(45.0, 6.25...)


Examples were copy pasted from the documentation.

more