Ask Your Question
0

How to find local minima of multi-parameter function?

asked 2020-02-16 06:19:30 -0500

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 flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
1

answered 2020-02-16 20:23:07 -0500

Sébastien gravatar image

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.

edit flag offensive delete link more
1

answered 2020-02-16 13:16:22 -0500

vdelecroix gravatar image

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 ])
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2020-02-16 06:19:30 -0500

Seen: 28 times

Last updated: Feb 16