On May 9, 2009, at 4:12 AM, Laurent Claessens wrote:
>
> I half-answer to myself :
>
>
>> 1. be able to convert a string into a function on which I can use
>> Sage
>
> s = "x**3"
> var('x')
> f = eval(s)
> print f(3)
Or
sage: SR(s)
x^3
sage: SR("2a+5x^2-sqrt(pi)")
5*x^2 + 2*a - sqrt(pi)
so you don't even have to make the variables ahead of time. (Also,
unless you are absolutely sure you trust the source of your string,
eval(s) can be dangerous.)
>
> makes the job
>
>> 2. from the results of Sage (especially from diff(f,x)), I need a
>> string that I can manipulate with Python (especially use the .replace
>> method in order to produce strings that are valid code for pstricks).
>
> s = "x**3"
> var('x')
> f = eval(s)
> print f(3)
> g = diff(f,x)
> print g
>
> I would like to get the string "3*(x**2)" or something like that.
What about
sage: repr(g)
'3*x^2'
- Robert
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---