Ask Your Question
0

get_minmax_data too generosous ?

asked 2012-04-08 11:32:35 +0100

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

Comments

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 ?

Laurent Claessens gravatar imageLaurent Claessens ( 2012-04-08 12:20:14 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-04-08 16:03:07 +0100

fidbc gravatar image

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)
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: 2012-04-08 11:32:35 +0100

Seen: 344 times

Last updated: Apr 08 '12