Ask Your Question
0

How to find local minima of multi-parameter function?

asked 2020-02-16 13:19:30 +0200

e372335 gravatar image

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:16:22 +0200

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
1

answered 2020-02-17 03:23:07 +0200

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

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 13:19:30 +0200

Seen: 729 times

Last updated: Feb 17 '20