On 7/24/10 4:38 AM, Renato wrote:
Hi, this seems very basic, but I wasn't able to figure it out. Let's say
I have a function:

sage: f(t)
-4*(5*sqrt(2)*cos(1/2*sqrt(2)*sqrt(5)) -
2*sqrt(5)*sin(1/2*sqrt(2)*sqrt(5)))*sin(1/2*sqrt(5)*t)/(sqrt(5)*sin(1/2*sqrt(2)*sqrt(5))^2
+ sqrt(5)*cos(1/2*sqrt(2)*sqrt(5))^2) +
4*(5*sqrt(2)*sin(1/2*sqrt(2)*sqrt(5)) +
2*sqrt(5)*cos(1/2*sqrt(2)*sqrt(5)))*cos(1/2*sqrt(5)*t)/(sqrt(5)*sin(1/2*sqrt(2)*sqrt(5))^2
+ sqrt(5)*cos(1/2*sqrt(2)*sqrt(5))^2) - 8

how do I tell sage to evaluate numerically everything but sin(), cos()
and t? I.e. I know this function is in the form

f(t) = a*sin(b*t) + c*cos(d*t)

can I tell sage to put it in this form, evaluating numerically a,b,c
and d?

kind regards
renato



It looks like there is also a -8 at the end:

sage: f(t)=-4*(5*sqrt(2)*cos(1/2*sqrt(2)*sqrt(5)) -2*sqrt(5)*sin(1/2*sqrt(2)*sqrt(5)))*sin(1/2*sqrt(5)*t)/(sqrt(5)*sin(1/2*sqrt(2)*sqrt(5))^2+ sqrt(5)*cos(1/2*sqrt(2)*sqrt(5))^2) +4*(5*sqrt(2)*sin(1/2*sqrt(2)*sqrt(5)) +2*sqrt(5)*cos(1/2*sqrt(2)*sqrt(5)))*cos(1/2*sqrt(5)*t)/(sqrt(5)*sin(1/2*sqrt(2)*sqrt(5))^2+ sqrt(5)*cos(1/2*sqrt(2)*sqrt(5))^2) - 8

sage: f.subs_expr(sqrt(5)==sqrt(5).n(),sqrt(2)==sqrt(2).n())
t |--> 8.13039327042996*sin(1.11803398874989*t) + 12.5656955743861*cos(1.11803398874989*t) - 8

Basically, I used subs_expr to subsititute in numeric values for the square roots.

Question to the community at large:

It seems like f.n() should do the above (evaluate what it can numerically, leave the variables alone). But this doesn't work:

sage: f.n()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/Users/grout/<ipython console> in <module>()

/Users/grout/sage/local/lib/python2.6/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.n (sage/symbolic/expression.cpp:17042)()

TypeError: cannot evaluate symbolic expression numerically


Thanks,

Jason


--
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
URL: http://www.sagemath.org

Reply via email to