On Fri, Apr 6, 2012 at 3:54 PM, vweber <[email protected]> wrote:

> Dear All
>
> One of the most appropriate solution to my problem would be:
>
> with this test case
> F=F1*cos(x*F2)+exp(F1-F2)
> F1=x*exp(x)
> F2=x+F3
> F3=sin(x)
>
>
> from sympy import *
> x=symbols('x')
> F1=Function('F1')(x)
> F2=Function('F1')(x)
> F3=Function('F3')(x)
> eqs=[]
> eqs.append(sin(x))
> eqs.append(x+F3)
> eqs.append(x*exp(x))
> eqs.append(F1*cos(x*F2)+exp(F1-F2))
> deqs=[]
> for eq in eqs:
>    deqs.append(diff(eq,x))
>
> >>> eqs
> [sin(x), x + F3(x), x*exp(x), F1(x)*cos(x*F1(x)) + 1]
> >>> deqs
> [cos(x), Derivative(F3(x), x) + 1, x*exp(x) + exp(x), -
> (x*Derivative(F1(x), x) + F1(x))*F1(x)*sin(x*F1(x)) +
> cos(x*F1(x))*Derivative(F1(x), x)]
>
>
> so I get all the ingredients I need in a compact way, but I would need
> to finally convert the
> Functions and their derivatives to symbols, eg
>
> Derivative(F3(x), x)  -->  dF3dx
> F1(x)  -->>  F1
>
> what would be the simplest way to do that?
>
>
You just have to know how to grab the names of the objects and build your
own string for the symbol. Something like this:

>>> d
Derivative(f(x), x, x, x)
>>> func, vars = d.expr, d.variables
>>> Symbol('d%i%sd%s%i' % (len(vars), func, vars[0], len(vars)))
d3f(x)dx3
>>> Symbol('d%i%s_d%s%i' % (len(vars), func, vars[0], len(vars)))
d3f(x)_dx3

If you are only working with first derivatives in one variable the
preceding could be simpler.

As for functions, the func attribute will give you the name of the function.

>>> Function('f1')(x)
f1(x)
>>> Symbol(str(_.func))
f1

/c

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
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/sympy?hl=en.

Reply via email to