kill(all)$

hamiltonian (=H) from  lagrangian( = L ): use legendre transformation. 'version 1.0'
peter.vlasschaert@gmail.com,27/10/2019

definition : hamiltonian 
=================

ham(pp,qq,nn,L):= block([],
h:sum(pp*qq,i,1,n)-L);

info :
===

pp: momentum
qq : general velocities 
L = T-V
========================
T : kinetic energy
V: potential energy
-------------------------------------------
L = L(q[i],d (q[i])/dt,t)   
H = H (q[i],p[i],t)           => ham, 'see above'

rem : arguments from ham definition  ' = atomic variables'

rem : {pp,qq} may not be local variables
==============================
result :[], block statement

ham(p[i],'diff(q[i],t),n,L);

pp(qq,L):= 'diff(L,qq);

pp(dotq[i],L);

rem : dotq[i]='diiff(q[i],t)

 => finite dimension of  n, n= integer

rem q[i] = ('diff(p[i],t,1)).
======================
' : protect against evaluation.

subst([n=3],ham(p[i],'diff(q[i],t),n,L)),simpsum:true;

see : 'youtube' 
https://www.youtube.com/watch?v=hGS_rclJttY

problem : plane fly x direction @ heigth y , plane has mass = m

how to solve problem:
=================
n =2   space : x,y

1e)  find  'L'
=========
L = T-V
g : 9.81 m/s^2  ' acceleration for mass : m '

p1:T = 1/2*m*vx^2;
p1a:T = 1/2*m*('diff(q[1],t)^2);
p2:V = m*g *y;

p3:L = rhs(p1) -rhs(p2);
p3a:L = rhs(p1a) -rhs(p2);

2e) ham , calculation
================

p4:subst([n=2],ham(p[i],'diff(q[i],t),n,L)),simpsum:true;

a) find p1:
--------------

p5:p[1]= subst([p3],pp(vx,L));

p5a:p[1] =ev(rhs(p5),nouns);

b) find p2:
--------------

velocity : vy  

p6: vy = 'diff(y,t);

p6a:p[2]=subst([p3],pp(vy,L));

p6b:p[2]=ev(rhs(p6a),nouns);

c : find :('diff(q[1],t,1)),('diff(q[2],t,1))
------------------------------------------------

p7a:'diff(q[1],t)  = vx;
p7b:'diff(q[2],t)  = vy;

d: final result
-----------------

p8:H=subst([p3,p5a,p6b,p7a,p7b],p4);

rem :  H = T + V  : 'definition'

p9a:H = subst([p1a,p2],T+V);

p9b:H = subst([p1,p2],T+V);