# Evaluating large expression with differential equations constraints

Consider the following lagrangian for a system, with $\theta$ and $r$ being the system coordinates:

$L = 2m\dot{r}^2+\frac{1}{2}mr^2\dot\theta^2-gmr(3-\cos\theta)$

Which gives us the following differential system:

$4m\ddot r-mr\dot \theta^2+gm(3-\cos\theta) = 0$

$2mr\dot \theta \dot r+mr^2\ddot \theta+gmr\sin\theta = 0$

And take the following function:

$H = r^2 \dot \theta \left (\dot r \cos \frac{\theta}{2} - \frac{r\dot \theta}{2} \sin \frac{\theta}{2} \cos^2 \frac{\theta}{2} \right)$

Now proof, with Maple (or any CAS like SymPy, etc), that

$\frac{dH}{dt} = 0$ (that quantity is related to Noether's Theorem)

What I did was to define $L(r, \theta)$, $H(r, \theta)$, and using eval with the expression above and the differential system equations, but it returns the same expression:

Maple worksheet

How can I evaluate that expression using the differential system obtained from the lagrangian?

Below the two DEs (Euler-Lagrange equations) agree with what you gave.

I construct Hdef using the Legendre transformation of L.

I pass a set containing the two DEs as the third argument to Maple's simplify command. This is sometimes called "simplify with side-relations". And so I'm directing Maple to simplify diff(Hdef,t) subject to those side-relations.

restart;

with(Physics,diff):

L := 2*m*diff(r(t),t)^2 + 1/2*m*r(t)^2*diff(theta(t),t)^2
- g*m*r(t)*(3-cos(theta(t)));

2                           2
/ d      \    1       2 / d          \
L := 2 m |--- r(t)|  + - m r(t)  |--- theta(t)|  - g m r(t) (3 - cos(theta(t)))
\ dt     /    2         \ dt         /

Er := - diff(L,r(t)) + diff(diff(L, diff(r(t),t)),t) = 0;

2                                 /  2      \
/ d          \                                  | d       |
Er := -m r(t) |--- theta(t)|  + g m (3 - cos(theta(t))) + 4 m |---- r(t)| = 0
\ dt         /                                  |   2     |
\ dt      /

ETh := - diff(L,theta(t)) + diff(diff(L,diff(theta(t),t)),t) = 0;

/ d          \ / d      \
ETh := g m r(t) sin(theta(t)) + 2 m r(t) |--- theta(t)| |--- r(t)|
\ dt         / \ dt     /

/  2          \
2 | d           |
+ m r(t)  |---- theta(t)| = 0
|   2         |
\ dt          /

Hdef := diff(r(t),t)*diff(L, diff(r(t),t))
+ diff(theta(t),t)*diff(L, diff(theta(t),t))
- L;

2                           2
/ d      \    1       2 / d          \
Hdef := 2 m |--- r(t)|  + - m r(t)  |--- theta(t)|
\ dt     /    2         \ dt         /

+ g m r(t) (3 - cos(theta(t)))

simplify( diff(Hdef,t), {Er, ETh} );

0

• Actually the H was given (maybe the example is just wrong, sorry about that), but the simplify command was exactly what I needed, thanks! (and I had a typo when writing 'sin' in the screenshot, but it still didn't worked) Apr 21, 2016 at 18:16