kill(all)$

maxima  hamiltonian function ,version 1.0,part 1
peter.vlasschaert@gmail.com,29/03/2020

ref :https://en.wikipedia.org/wiki/Hamiltonian_mechanics

load : packages
============

load(lrats)$

intermezzo
========
H=H(x,y)

p1:H(x,y) ;

dH = total differential of two variables :{x,y}
----------------------------------------------------

p2:'diff(H) =diff(p1) ;

p3:[del(H)=dH,del(y) =dy,del(x)=dx];

p4:subst(p3,p2);

p5:expand(p4/dt);

p6:[dx/dt = f(x,y),dy/dt=g(x,y),dH/dt ='diff(p1,t)];

p6a:[dx/dt ='diff(x,t),dy/dt ='diff(y,t)];

p6b:lratsubst(p6a,p6);

rem :subst 'doesn't' work

p6c:makelist(rhs(p6b[i])=lhs(p6b[i]),i,1,length(p6b)-1);

p7:lratsubst(p6,lhs(p5))=lratsubst(p6,rhs(p5));

p7a:lratsubst(p6c,p7);

Hamiltonian = constant ,when rhs 'p7a' = 0
===============================

1e)  constraint
==========

p8a:'diff(y,t) = diff(H(x,y),x);
p8a1:p6b[2];
p8b:'diff(x,t) = -1*diff(H(x,y),y);
p8b1:p6b[1];
p8c:[p8a,p8b];

2e) subst of 1e)
============
use : p7a

p8d:lratsubst(p8c,p7a);

3e) solve
=======

p8e:integrate(p8d,t);

p8e1:H(x,y) = rhs(p8e);

rem :constant = %c1  here.

a) relation H(x,y)
============
use 1e)

p9a:lratsubst(p8a,p8a1)*(-1);
p9b:lratsubst(p8b,p8b1);

b) relation betrween :f(x,y) and g(x,y)
===========================

p10a:diff(p9a,y);
p10b:diff(p9b,x);

→  constraint  : between f(x,y) @ g(x,y)

p10c1:lratsubst(p10a,p10b);

physics :intermezzo
===============
https://en.wikipedia.org/wiki/Hamiltonian_mechanics

physics :  x  = p  (= momentum)  , y = q (= space)
=====================================

========================================================
momentum = mass*velocity  = m*v
space        = x or y or z                               , (1d =one dimension,distance)
========================================================
rem : H(x,y)  'math'  → H(p,q) 'physics'

example : physics , spring  : H(p,q) = 1/(2*m)*p^2+1/2*k*q^2
rem : k : spring constante.

physics : F (=force) = -k*x ( =newton's law =m*a)
====================================
a:acceleration

ODE2 :ordinary differential equations of second order
=======================================

p11:m*'diff(x,t,2) = -k*x;

use : solve schrodinger equation : H*ψ = E*ψ
=================================
E : energy
ψ : function 
H : operator working on ψ
==================================
ψ* = complex conjugate from ψ
==================================
example : ψ =a+%i*b  → ψ*=a-%i*b