Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hi,

It seems that P.get_minmax_data() returns the minmax data corresponding to the plot, not the function.

An option to get a local min of a function would be to use the minimize function, as in

sage: f(x) = sin(x)
sage: x0 = 1
sage: xn = minimize(f,[(x0)])[0]
Optimization terminated successfully.
         Current function value: -1.000000
         Iterations: 3
         Function evaluations: 6
         Gradient evaluations: 6
sage: f( xn )
-0.999999999995

For maximization we could call minimize with -f instead of f.

If minimizing or maximizing one variable functions over an interval we could use find_minimum_on_interval or find_maximum_on_interval respectively. For example

sage: (a,b) = (-pi/2,2*pi)
sage: find_minimum_on_interval(f,a,b)
(-1.0, 4.7123889767534486)

For more details on these functions you can check the Optimization section of the sage manual.


Note: calling find_maximum_on_interval(f,a,b) with f as defined above yields an error, this might be a bug. A workaround to this is to define f with

sage: f = lambda x: sin(x)