Hi William,
I just stumbled over this message and found that the following is even
faster:
var('t')
W(t)=95*sqrt(t)*sin(t/6)^2
R(t)=275*sin(t/3)^2
F = (W-R)._fast_float_('t')
def A(t):
return 1200 + numerical_integral(F,0,t)[0]
plot(A, (t,0,18))
For reasons I have still not understood, fast_float works faster if the
variables are set in quotation marks. I still can't find anything about
fast_float in the Sage Reference Manual. For example, I would like to
know how something like this is handled:
var('a t')
F = fast_float(a*t^2 + a*t + a, 'a', 't')
How would I plot F or find its root for a fixed a? plot(F(1,t),(t,-1,1))
does not work, nor does find_root(F(1,t), -1, 1).
Thanks for your help!
Stan
William Stein wrote:
> On Mon, Mar 30, 2009 at 2:16 PM, Jason Grout
> <[email protected]> wrote:
>
>> Chris Seberino wrote:
>>
>>> In a new sage session...
>>> (Notice the A(t) function returns values just fine. Why doesn't plot
>>> () like it?)
>>>
>>> sage: W(t)=95*sqrt(t)*sin(t/6)^2
>>>
>>> sage: R(t)=275*sin(t/3)^2
>>>
>>> sage: def A(t):
>>> ....: return 1200 + numerical_integral(W(x)-R(x),0,t)[0]
>>> ....:
>>>
>>> sage: A(0)
>>> 1200.0
>>>
>>> sage: A(18)
>>> 1309.788183281373
>>>
>>> sage: plot(A(t),(t,0,18))
>>> ---------------------------------------------------------------------------
>>> TypeError Traceback (most recent call
>>> last)
>>>
>>> /home/seb/<ipython console> in <module>()
>>>
>>> /home/seb/<ipython console> in A(t)
>>>
>>> /usr/local/sage-3.4-linux-PentiumM-ubuntu-8.04.1-i686-Linux/local/lib/
>>> python2.5/site-packages/sage/gsl/integration.so in
>>> sage.gsl.integration.numerical_integral (sage/gsl/integration.c:1953)
>>> ()
>>>
>>> TypeError: a float is required
>>>
>> That's weird. A workaround for now is the following:
>>
>
> It's not a weird -- A is a function, not a symbolic expression, so the
> right syntax is:
>
> plot(A, (t,0,18))
>
> Doing
>
> plot(A(t), (t,0,18))
>
> should never work.
>
> By the way, doing this is massively faster (10000 times faster?)
>
> W(t)=95*sqrt(t)*sin(t/6)^2
> R(t)=275*sin(t/3)^2
> F = (W-R)._fast_float_(t)
> def A(t):
> return 1200 + numerical_integral(F,0,t)[0]
>
> plot(A, (t,0,18))
>
> William
>
> William
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---