In [1]:
import sympy
In [2]:
x, u = sympy.symbols('x u', real=True)
In [3]:
U = sympy.Function('U')(x,u)
In [4]:
U
Out[4]:
In [12]:
x = sympy.Symbol('x',real=True)
In [13]:
y = sympy.Function('y')(x)
In [14]:
U = sympy.Function('U')(x,y)
X = sympy.Function('X')(x,y)
Y = sympy.Function('Y')(X)
In [15]:
sympy.pprint(sympy.diff(U,x))
In [18]:
sympy.pprint( sympy.diff(Y,x))
In [39]:
sympy.pprint( sympy.diff(Y,x).args[0] )
In [40]:
sympy.pprint( sympy.diff(U,x)/ sympy.diff(Y,x).args[0])
For $Y''(X)$,
In [51]:
YprimeX = sympy.diff(U,x)/sympy.diff(Y,x).args[0]
sympy.pprint( sympy.diff(YprimeX,x).simplify() )
In [32]:
sympy.factor_list( sympy.diff(Y,x)) # EY 20160522 I don't know how to simply obtain the factors of an expression
# EY 20160522 update resolved: look at above and look at this page; it explains all:
# http://docs.sympy.org/dev/tutorial/manipulation.html
Out[32]:
In [53]:
t, x, u, u_1, x_t, u_t, u_1t = sympy.symbols('t x u u_1 x_t u_t u_1t', real=True)
X = -u_1
U = u - x*u_1
U_1 = x
cf. How to do total derivatives: http://robotfantastic.org/total-derivatives-in-sympy.html
In [61]:
from sympy import Derivative, diff, expr
def difftotal(expr, diffby, diffmap):
"""Take the total derivative with respect to a variable.
Example:
theta, t, theta_dot = symbols("theta t theta_dot")
difftotal(cos(theta), t, {theta: theta_dot})
returns
-theta_dot*sin(theta)
"""
# Replace all symbols in the diffmap by a functional form
fnexpr = expr.subs({s:s(diffby) for s in diffmap})
# Do the differentiation
diffexpr = diff(fnexpr, diffby)
# Replace the Derivatives with the variables in diffmap
derivmap = {Derivative(v(diffby), diffby):dv
for v,dv in diffmap.iteritems()}
finaldiff = diffexpr.subs(derivmap)
# Replace the functional forms with their original form
return finaldiff.subs({s(diffby):s for s in diffmap})
In [63]:
difftotal( U,t,{x:x_t, u:u_t, u_1:u_1t}) + (-U_1)* (-u_1t)
Out[63]:
This transformation is the Legendre transformation
cf. 4. Exercises Chapter 2 Lie Transformations Introduction to Differential Invariants.
Consider transformation $(x,u)=(x,u(x)) \to (X,U)=(X(x,u),U(x,u))=(u,x)$. Let $Y=Y(X)$. $Y(X) \in \Gamma(\mathbb{R}^1 \times \mathbb{R}^1)$, i.e. $Y(X)$ is a section. So $Y(X) = Y(X(x,u)) = U(x,u)$. And so in this case, $Y(X(x,u))=Y(u)=U(x,u) = x$
In [65]:
x = sympy.Symbol('x',real=True)
u = sympy.Function('u')(x)
U = x
X = u
Y = sympy.Function('Y')(X)
In [66]:
sympy.pprint( sympy.diff(Y,x))
In [67]:
sympy.pprint(sympy.diff(U,x))
And so $Y'(X)$ is
In [68]:
sympy.pprint( 1/ sympy.diff(Y,x).args[0])
And so $Y''(X)$ is
In [70]:
sympy.pprint( sympy.diff( 1/ sympy.diff(Y,x).args[0], x))
cf. (2) from 4. Exercises, Chapter 2 Lie Transformations pp. 20
Recall an arbitrary point transformation:
In [71]:
x = sympy.Symbol('x',real=True)
In [72]:
y = sympy.Function('y')(x)
In [73]:
U = sympy.Function('U')(x,y)
X = sympy.Function('X')(x,y)
Y = sympy.Function('Y')(X)
In [74]:
sympy.pprint(sympy.diff(U,x))
In [75]:
sympy.pprint( sympy.diff(Y,x))
In [76]:
sympy.pprint( sympy.diff(Y,x).args[0] )
In [77]:
sympy.pprint( sympy.diff(U,x)/ sympy.diff(Y,x).args[0])
For $Y''(X)$,
In [79]:
YprimeX = sympy.diff(U,x)/sympy.diff(Y,x).args[0]
Yprime2X = sympy.diff(YprimeX,x)
sympy.pprint( Yprime2X.simplify() )
In [ ]: