Hausaufgabe 3: A7
Pendel mit bewegter Aufhängung

by Jan Totz, jantotz@itp.tu-berlin.de

Code

lagrangianEquations[T_,V_,Q_:0,genCoords_List]:=Module[{L=T-V},(D[D[L,D[#[t],t]],t]==Q+D[L,#[t]])&/@genCoords];

Problems

Example: harmonic oscillator

Clear[m,k]
genCoords={x};
T=1/2 m x'[t]^2;
V=1/2k x[t]^2;
Q=0;
ic=Thread[{x[0],x'[0]}=={1.0,0.0}];

lagrangianEquations[T,V,Q,genCoords]
DSolve[lagrangianEquations[T,V,Q,genCoords],genCoords,t]
DSolve[{lagrangianEquations[T,V,Q,genCoords],ic},genCoords,t]

m=1.0;
k=1.0;
sol=NDSolve[{lagrangianEquations[T,V,Q,genCoords],ic},genCoords,{t,0,20}];
Plot[x[t]/.sol,{t,0,20},Frame->True,FrameLabel->{"t","x(t)"}]
Manipulate[Graphics[{Disk[{#,0}]},PlotRange->{{-3,5},{-2,2}},Frame->True]&@Evaluate[x[t]/.sol][[1]],{t,0,20,0.1,Appearance->"Open"},TrackedSymbols->{t}]

a) Kreisbahn

m=1.0;
l=1.0;
r=1.0;
ω=0.1;
g=10;

genCoords={ϕ};
T=1/2 m (ω^2 r^2+l^2 ϕ'[t]^2+2ω r l ϕ'[t] Sin[ϕ[t]-ω t]);
V=m g (r Sin[ω t]-l Cos[ϕ[t]]);
Q=0;
ic=Thread[{ϕ[0],ϕ'[0]}=={1.0,0.0}];

lagrangianEquations[T,V,Q,genCoords]
(*DSolve[lagrangianEquations[T,V,Q,genCoords],genCoords,t]*)

tfinal=2π/ω ;
sol=NDSolve[{lagrangianEquations[T,V,Q,genCoords],ic},genCoords,{t,0,tfinal}];
Plot[ϕ[t]/.sol,{t,0,20},Frame->True,FrameLabel->{"t","ϕ(t)"}]
Manipulate[Graphics[{Circle[{0,0},r],Line[{{r Cos[ω t],r Sin[ω t]},{r Cos[ω t]+l Sin[#],r Sin[ω t]-l Cos[#]}}],Disk[{r Cos[ω t],r Sin[ω t]},0.05],Disk[{r Cos[ω t]+l Sin[#],r Sin[ω t]-l Cos[#]},0.2]},PlotRange->2.5{{-1,1},{-1,1}},Frame->True,FrameLabel->{"x","y"},FrameStyle->Directive[Black,20,AbsoluteThickness[2]],RotateLabel->False,PlotLabel->Style["t = "<>ToString@NumberForm[t,{Infinity,1}],Black,20]]&@Evaluate[ϕ[t]/.sol][[1]],{t,0,tfinal,0.1,Appearance->"Open",AnimationRate->4},TrackedSymbols->{t}]

b) horizontale Bewegung

m=1.0;
l=1.0;
r=1.0;
ω=0.1;
g=10;

genCoords={ϕ};
T=1/2 m (l^2 ϕ'[t]^2+ω^2 r^2 Sin[ω t]^2-ω r l ϕ'[t] Sin[ω t]Cos[ϕ[t]]);
V=-m g l Cos[ϕ[t]];
Q=0;
ic=Thread[{ϕ[0],ϕ'[0]}=={1.0,0.0}];

lagrangianEquations[T,V,Q,genCoords]

tfinal=2π/ω ;
sol=NDSolve[{lagrangianEquations[T,V,Q,genCoords],ic},genCoords,{t,0,tfinal}];
Plot[ϕ[t]/.sol,{t,0,20},Frame->True,FrameLabel->{"t","ϕ(t)"}]
Manipulate[Graphics[{Line[{{-2.5,0},{2.5,0}}],Line[{{r Cos[ω t],0},{r Cos[ω t]+l Sin[#],-l Cos[#]}}],Disk[{r Cos[ω t],0},0.05],Disk[{r Cos[ω t]+l Sin[#],-l Cos[#]},0.2]},PlotRange->2.5{{-1,1},{-1,1}},Frame->True,FrameLabel->{"x","y"},FrameStyle->Directive[Black,20,AbsoluteThickness[2]],RotateLabel->False,PlotLabel->Style["t = "<>ToString@NumberForm[t,{Infinity,1}],Black,20]]&@Evaluate[ϕ[t]/.sol][[1]],{t,0,tfinal,0.1,Appearance->"Open",AnimationRate->4},TrackedSymbols->{t}]

c) vertikale Bewegung

m=1.0;
l=1.0;
r=1.0;
ω=0.1;
g=10;

genCoords={ϕ};
T=1/2 m (l^2 ϕ'[t]^2+ω^2 r^2 Sin[ω t]^2-ω r l ϕ'[t] Sin[ω t]Sin[ϕ[t]]);
V=m g (r Cos[ω t]-l Cos[ϕ[t]]);
Q=0;
ic=Thread[{ϕ[0],ϕ'[0]}=={1.0,0.0}];

lagrangianEquations[T,V,Q,genCoords]

tfinal=2π/ω ;
sol=NDSolve[{lagrangianEquations[T,V,Q,genCoords],ic},genCoords,{t,0,tfinal}];
Plot[ϕ[t]/.sol,{t,0,20},Frame->True,FrameLabel->{"t","ϕ(t)"}]
Manipulate[Graphics[{Line[{{0,-2.5},{0,2.5}}],Line[{{0,r Sin[ω t]},{l Sin[#],r Sin[ω t]-l Cos[#]}}],Disk[{0,r Sin[ω t]},0.05],Disk[{l Sin[#],r Sin[ω t]-l Cos[#]},0.2]},PlotRange->2.5{{-1,1},{-1,1}},Frame->True,FrameLabel->{"x","y"},FrameStyle->Directive[Black,20,AbsoluteThickness[2]],RotateLabel->False,PlotLabel->Style["t = "<>ToString@NumberForm[t,{Infinity,1}],Black,20]]&@Evaluate[ϕ[t]/.sol][[1]],{t,0,tfinal,0.1,Appearance->"Open",AnimationRate->4},TrackedSymbols->{t}]