Sei sulla pagina 1di 4

> restart; > x:=L*sin(theta(t)); (1) > y:=-L*cos(theta(t)); (2) > Ek:=1/2*m*(diff(x,t)^2+diff(y,t)^2); (3) > Ep:=m*g*y; (4) >

Lagrangian:=Ek-Ep; (5)

> # the canonical variable is omega=diff(theta,t) so: > Lagrangian2:=subs(diff(theta(t),t)=omega(t),Lagrangian); (6) > # giving different names as Maple does not like differentiation with respect to functions > # besides names become shorter; we do it with list of substitution (handy!) > transf := {theta(t)=th,omega(t)=om}; (7) > transfback := {th=theta(t),om=omega(t)}; (8) > Lagrangian3:=subs(transf,Lagrangian2); (9) > DiffLToTheta:=diff(Lagrangian3,th); (10) > DiffLToOmega:=diff(Lagrangian3,om); (11) > # One Lagrange equation: ddt DiffLToOmega - DiffLToTheta > # but before diff to t we have to make function, then

> differentiate, and transform back > zero2 := simplify(diff(subs(transfback, DiffLToOmega),t) - subs (transfback, DiffLToTheta)); (12) > # we already defined > zero1 := diff(theta(t),t) - omega(t); (13) > # these are the first order ODE which are suited for a matlabprogram > ODEs:=solve({zero1, zero2}, {diff(omega(t),t),diff(theta(t),t)}); (14) > # this I used for constructing the function rhside.m > (15) >

(16) > (17) > (18) >

0 10 20 t 30 40 50

>

0 2 4 t 6 8 10

> >

Potrebbero piacerti anche