# get_minmax_data too generosous ?

Hello

I'd like to understand the rationale behind the ymin value in the get_minmax_data of a parametric curve that have always y=0:

sage: f(x)=sin(x)
sage: g(x)=0
sage: P=parametric_plot((f,g),(-pi/2,2*pi))
sage: P.get_minmax_data()['ymin']
-1.0


I would have expected ymin to be 0. Is is a bug or is it something I don't understand ?

edit retag close merge delete

By the way, what is the correct way to know the global xmin,xmax,ymin and ymax of a function ? A 3-digit approximation is enough. Up to now I'm using get_minmax_data, but is it the correct way ?

Sort by » oldest newest most voted 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)])
Optimization terminated successfully.
Current function value: -1.000000
Iterations: 3
Function 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)

more