I'm not sure what exactly is happening, but it might be some side
effect of redefining f and g inside the function.  The following
version works for me:

def shaded_area_plot(f,g,c,d,a,b):
    """
    Plots functions f and g from c to d and shades the region between
them from a to b.
    """
    from sage.ext.fast_eval import fast_float
    f1 = fast_float(f)
    g1 = fast_float(g)
    step = 0.01
    vf = [(x,f1(x)) for x in srange(a, (b+step), step)]
    vg = [(x,g1(x)) for x in srange(b, (a-step), -step)]
    sha = polygon(vf + vg, rgbcolor='grey')
    return(plot(f1, (c,d)) + plot(g1, (c,d), rgbcolor='red') + sha)

-M. hampton

On Nov 14, 1:12 am, pong <[EMAIL PROTECTED]> wrote:
> Also, let me apologize in advance if that's because some bugs in my
> script. But I hope someone can tell me why that's happening.
>
> On Nov 13, 11:10 pm, pong <[EMAIL PROTECTED]> wrote:
>
> > While working with fast_float, I find something extremely puzzling!
> > It's hard to explain but let me try:
>
> > 0) I define shade_are_plot
> > 1) I run shade_area_plot( f1,g1, a1, b1, c1, d1)
> > 2) I restart the worksheet
> > 3) I run the definition cell again
> > 4) I run shade_area_plot(f2, g2, a2, b2, c2, d2)
>
> > SAGE shows me the first plot (i.e. in the plot produced in (1)), if I
> > run step (4) again, SAGE will then show me the shaded area between f2
> > and g2. In general, if I restart the worksheet again and run
> > shade_area_plot on another two graphs, SAGE will show me the first 2
> > plots before show me the plot that I want.
>
> > Why?
>
> > On Nov 13, 1:59 pm, Robert Bradshaw <[EMAIL PROTECTED]>
> > wrote:
>
> > > On Nov 13, 2008, at 1:22 PM, pong wrote:
>
> > > > Thanks.
>
> > > > Where can I find out more about fast_float?
> > > > Even after importing fast_float, "fast_float?" does not show any
> > > > useful information.
>
> > > Try typing sage.ext.fast_eval?
>
> > > > Is it related to fast_arith?
>
> > > No, completely orthogonal despite the name.
>
> > > > On Nov 12, 7:56 pm, Robert Bradshaw <[EMAIL PROTECTED]>
> > > > wrote:
> > > >> On Nov 12, 2008, at 5:52 PM, kcrisman wrote:
>
> > > >>>> put those three lines in where indicated and it will be orders of
> > > >>>> magnitude faster for most cases, plus will handle constants, lambda
> > > >>>> functions, etc., automatically.
>
> > > >>>> fast_float is one of Sage's coolest "secrets".
>
> > > >> Thanks :)
>
> > > >>> That brings up a question I've had for a while.  When is it good to
> > > >>> use fast_float (I've seen a lot of code over the last few months
> > > >>> which
> > > >>> replaces other calls with it) and when is it not good, or for
> > > >>> instance
> > > >>> when might RR be better, or just nothing?  E.g. William's
> > > >>> examples on
> > > >>> the interact wiki use it, but the others don't.  Given the
> > > >>> limitations
> > > >>> of our Sage server, something like that could really help things
> > > >>> if it
> > > >>> really speeded it up.  Unfortunately, as a non-CS type the
> > > >>> documentation just doesn't compute for me, and just seeing a
> > > >>> couple of
> > > >>> examples where it is good to use it and where it isn't would be very
> > > >>> helpful.
>
> > > >>> For instance, should it only be used in .py files, or is it
> > > >>> worthwhile
> > > >>> in the command line or notebook?  Is it worth using if something is
> > > >>> evaluated fewer than (say) 100 times?  Can it be interspersed
> > > >>> with ZZ
> > > >>> (I assume not) or RR(n), say RR(1000) (I have no idea)?  Thanks for
> > > >>> any examples, especially from non-high-performance situations
> > > >>> where it
> > > >>> still might speed things up considerably (or do something bad).
>
> > > >> The fast_float functionality is mostly for internal use, and is
> > > >> useful when one wants to evaluate an expression to double floating-
> > > >> point (i.e. 53-bits using the machine's native arithmetic) lots of
> > > >> times. "Lots" depends on the application, but is probably in the
> > > >> neighborhood of 10-100+, depending on the complexity of the equation
> > > >> and whether or not it has any symbolic values like pi (which slow
> > > >> down "normal" evaluation via maxima a huge amount). Thus it is suited
> > > >> to things like plotting or numerical integration. However, most such
> > > >> functions internally construct fast_float objects, so there usually
> > > >> is no need for the user to do so.
>
> > > >> That being said, there are plenty of use cases for it for end users.
> > > >> On the interact wiki (looking at the calculus page) it seems that
> > > >> fast_float is used when the function is evaluated a lot, and not when
> > > >> it is just passed off to something else (e.g. to contour_plot which
> > > >> (should) use the fast_float internally). The usage in "Coordinate
> > > >> Transformations" is probably redundant, as parametric_plot should be
> > > >> calling fast_float itself.
>
> > > >> Not sure it completely answers your question, but hopefully it helps.
>
> > > >> - Robert
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to