ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 08 Apr 2012 09:03:07 -0500get_minmax_data too generosous ?https://ask.sagemath.org/question/8867/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 ?
Sun, 08 Apr 2012 04:32:35 -0500https://ask.sagemath.org/question/8867/get_minmax_data-too-generosous/Comment by Laurent Claessens for <p>Hello </p>
<p>I'd like to understand the rationale behind the <code>ymin</code> value in the get_minmax_data of a parametric curve that have always y=0:</p>
<pre><code>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
</code></pre>
<p>I would have expected ymin to be 0. Is is a bug or is it something I don't understand ?</p>
https://ask.sagemath.org/question/8867/get_minmax_data-too-generosous/?comment=19968#post-id-19968By 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 ?Sun, 08 Apr 2012 05:20:14 -0500https://ask.sagemath.org/question/8867/get_minmax_data-too-generosous/?comment=19968#post-id-19968Answer by fidbc for <p>Hello </p>
<p>I'd like to understand the rationale behind the <code>ymin</code> value in the get_minmax_data of a parametric curve that have always y=0:</p>
<pre><code>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
</code></pre>
<p>I would have expected ymin to be 0. Is is a bug or is it something I don't understand ?</p>
https://ask.sagemath.org/question/8867/get_minmax_data-too-generosous/?answer=13438#post-id-13438Hi,
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](http://x0.no/3s96) 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)
Sun, 08 Apr 2012 09:03:07 -0500https://ask.sagemath.org/question/8867/get_minmax_data-too-generosous/?answer=13438#post-id-13438