Preliminaries
Subroutines phasePlot
phasePlot@q_, p_, tList_List, opts___D :=
ParametricPlot@ 8q, p< Evaluate, tList, opts, PlotRange -> All,
Axes -> False, PlotLabel -> "Phase Diagram", Frame -> True,
FrameLabel -> 8"q", "q
"<, RotateLabel ® False, AspectRatio -> 1 D
H*Example*L phasePlot@Sin@2 Π tD, D@Sin@2 Π tD, tD, 8t, 0, 10<D
-1.0 -0.5 0.0 0.5 1.0
-6
-4
-2
0
2
4
6
q
q
Phase Diagram
diffSeriesOne
diffSeriesOne@eq_, z_, t_, initialx_, initialv_, order_D :=
Module@ 8tempser, tempeq, tempvar, tempsol, tempinit<,
tempser = z ® Series@z, 8t, 0, order<D;
tempeq = HHeq@@1DD - eq@@2DDL . tempserL 0;
tempvar = HTable@D@z, 8t, j<D, 8j, 2, order + 2<D . t ® 0L Flatten;
tempsol = Solve@tempeq, tempvarD Flatten;
tempinit = 8Head@zD@0D ® initialx, Head@zD'@0D ® initialv<;
z . tempser . tempsol . tempinitD
H*Example*L diffSeriesOne@y''@tD + Γ y'@tD^2 + Ω^2 y@tD 0, y@tD, t, 1, 0, 2D
1 -
Ω2 t2
2+ O@tD3
H*Internals of diffSeriesOne*L
wrap
wrap@Θ_D := Mod@Θ, 2 Π, -ΠD;
H*Example*L Plot@wrap@ΘD, 8Θ, -4 Π, 4 Π<, AspectRatio ® 0.25,
Ticks ® 8Table@n Π, 8n, -4, 4<D, Table@n Π 2, 8n, -4, 4<D<D
-4 Π -3 Π -2 Π -Π Π 2 Π 3 Π 4 Π
-Π
-Π
2
Π
2
Π
solnPend
solnPend@8Θ0_, dΘ0_<, 8Β_, f0_, Ω0_, Ωd_<, tstart_, tend_, tstep_, opts___D :=
HNDSolve@8dΘ'@tD + Β dΘ@tD + Ω0^2 Sin@Θ@tDD == f0 Cos@Ωd tD,
dΘ@tD == Θ'@tD,
Θ@0D Θ0,
dΘ@0D dΘ0<,
8dΘ@tD, Θ@tD<, 8t, tstart, tend<, MaxSteps ® tstepD FlattenL@@2DD@@2DD
anglePend
anglePend@8Θ0_, dΘ0_<, 8Β_, f0_, Ω0_, Ωd_<, tstart_, tend_, tstep_, opts___D :=
Module@8temp<,
temp = NDSolve@8dΘ'@tD + Β dΘ@tD + Ω0^2 Sin@Θ@tDD == f0 Cos@Ωd tD,
dΘ@tD == Θ'@tD,
Θ@0D Θ0,
dΘ@0D dΘ0<,
8dΘ@tD, Θ@tD<, 8t, tstart, tend<, MaxSteps ® tstepD Flatten;
Plot@Θ@tD . temp, 8t, tstart, tend<, opts, AxesLabel ® 8"t", "Θ"<DD
anglePendw@8Θ0_, dΘ0_<, 8Β_, f0_, Ω0_, Ωd_<, tstart_, tend_, tstep_, opts___D :=
Module@8temp<,
temp = NDSolve@8dΘ'@tD + Β dΘ@tD + Ω0^2 Sin@Θ@tDD == f0 Cos@Ωd tD,
dΘ@tD == Θ'@tD,
Θ@0D Θ0,
dΘ@0D dΘ0<,
8dΘ@tD, Θ@tD<, 8t, tstart, tend<, MaxSteps ® tstepD Flatten;
Plot@wrap@Θ@tD . tempD, 8t, tstart, tend<, opts, AxesLabel ® 8"t", "Θ"<DD
2 nonlinear_oscillations.nb
phasePend
phasePend@8Θ0_, dΘ0_<, 8Β_, f0_, Ω0_, Ωd_<, tstart_, tend_, tstep_, opts___D :=
ModuleA8temp<,
temp = NDSolve@8dΘ'@tD + Β dΘ@tD + Ω0^2 Sin@Θ@tDD == f0 Cos@Ωd tD,
dΘ@tD == Θ'@tD,
Θ@0D Θ0,
dΘ@0D dΘ0<,
8dΘ@tD, Θ@tD<, 8t, tstart, tend<, MaxSteps ® tstepD Flatten;
ParametricPlotA8Θ@tD, dΘ@tD< . temp, 8t, tstart, tend<, opts, AxesLabel ® 9"Θ", "Θ
"=EE
phasePendw@8Θ0_, dΘ0_<, 8Β_, f0_, Ω0_, Ωd_<, tstart_, tend_, tstep_, opts___D :=
ModuleA8temp<,
temp = NDSolve@8dΘ'@tD + Β dΘ@tD + Ω0^2 Sin@Θ@tDD == f0 Cos@Ωd tD,
dΘ@tD == Θ'@tD,
Θ@0D Θ0,
dΘ@0D dΘ0<,
8dΘ@tD, Θ@tD<, 8t, tstart, tend<, MaxSteps ® tstepD Flatten;
ParametricPlotA8wrap@Θ@tD . tempD, dΘ@tD . temp<, 8t, tstart, tend<, opts,
Ticks ® 8Table@n Π 2, 8n, -2, 2<D, Automatic<, AxesLabel ® 9"Θ", "Θ
"=EE
poincarePend
poincarePend@8Θ0_, dΘ0_<, 8Β_, f0_, Ω0_, Ωd_<, tstart_, tend_, step_, opts___D :=
ModuleA8temp1, temp2<,
temp1 = NDSolve@8dΘ'@tD + Β dΘ@tD + Ω0^2 Sin@Θ@tDD == f0 Cos@Ωd tD,
dΘ@tD == Θ'@tD,
Θ@0D Θ0,
dΘ@0D dΘ0<,
8dΘ@tD, Θ@tD<, 8t, 0, tend<, MaxSteps ® stepD Flatten;
temp2 = Table@8Θ@tD, dΘ@tD< . temp1, 8t, tstart, tend, 2 Π Ωd<D;
ListPlotAtemp2, PlotStyle -> [email protected], opts, AxesLabel ® 9"Θ", "Θ
"=EE
poincarePendw@8Θ0_, dΘ0_<, 8Β_, f0_, Ω0_, Ωd_<, tstart_, tend_, step_, opts___D :=
ModuleA8temp1, temp2<,
temp1 = NDSolve@8dΘ'@tD + Β dΘ@tD + Ω0^2 Sin@Θ@tDD == f0 Cos@Ωd tD,
dΘ@tD == Θ'@tD,
Θ@0D Θ0,
dΘ@0D dΘ0<,
8dΘ@tD, Θ@tD<, 8t, 0, tend<, MaxSteps ® stepD Flatten;
temp2 = Table@8wrap@Θ@tD . temp1D, dΘ@tD . temp1<, 8t, tstart, tend, 2 Π Ωd<D;
ListPlotAtemp2, PlotStyle -> [email protected], opts, AxesLabel ® 9"Θ", "Θ
"=EE
nonlinear_oscillations.nb 3
solnDuff
solnDuff@8x0_, v0_<, 8a_, b_, c_, f0_, Ωd_<, tstart_, tend_, tstep_, opts___D :=
HNDSolve@8v'@tD + a x@tD + b x@tD^3 + c v@tD == f0 Cos@Ωd tD,
v@tD x'@tD,
x@0D x0,
v@0D v0<,
8v@tD, x@tD<, 8t, tstart, tend<, MaxSteps ® tstepD FlattenL@@2DD@@2DD
posDuff
posDuff@8x0_, v0_<, 8a_, b_, c_, f0_, Ωd_<, tstart_, tend_, tstep_, opts___D :=
Module@8temp<,
temp = NDSolve@8v'@tD + a x@tD + b x@tD^3 + c v@tD == f0 Cos@Ωd tD,
v@tD x'@tD,
x@0D x0,
v@0D v0<,
8v@tD, x@tD<, 8t, tstart, tend<, MaxSteps ® tstepD Flatten;
Plot@x@tD . temp, 8t, tstart, tend<, opts, AxesLabel ® 8"t", "x"<DD
phaseDuff
phaseDuff@8x0_, v0_<, 8a_, b_, c_, f0_, Ωd_<, tstart_, tend_, tstep_, opts___D :=
Module@8temp<,
temp = NDSolve@8v'@tD + a x@tD + b x@tD^3 + c v@tD == f0 Cos@Ωd tD,
v@tD x'@tD,
x@0D x0,
v@0D v0<,
8v@tD, x@tD<, 8t, tstart, tend<, MaxSteps ® tstepD Flatten;
ParametricPlot@8x@tD, v@tD< . temp, 8t, tstart, tend<, opts, AxesLabel ® 8"x", "v"<DD
poincareDuff
poincareDuff@8x0_, v0_<, 8a_, b_, c_, f0_, Ωd_<, tstart_, tend_, tstep_, opts___D :=
Module@8temp<,
temp1 = NDSolve@8v'@tD + a x@tD + b x@tD^3 + c v@tD == f0 Cos@Ωd tD,
v@tD x'@tD,
x@0D x0,
v@0D v0<,
8v@tD, x@tD<, 8t, tstart, tend<, MaxSteps ® tstepD Flatten;
temp2 = Table@8x@tD, v@tD< . temp1, 8t, tstart, tend, 2 Π Ωd<D;
ListPlot@temp2, PlotStyle -> [email protected], opts, AxesLabel ® 8"x", "v"<DD
4 nonlinear_oscillations.nb
psdPlot
psdListPlot@data_, fs_, opts___D :=
Module@8specraw2, fvec, datlist<,
specraw2 = Fourier@dataD;
specraw = Hspecraw2@@1 ;; Round@Length@specraw2D 2DDDL Chop Flatten;
fvec = Range@0, fs 2, fs 2 HLength@specrawD - 1LD;
datlist = Table@8fvec@@ssDD, Abs@specraw@@ssDDD<, 8ss, 1, Length@specrawD<D;
ListLogPlot@datlist, opts, Joined ® True, PlotRange ® AllDD
H*example*L Module@8dt, Npts, sampledata, freqlist, amplist, sig, sigsig, i<,
dt = 0.01; H*sec*LNpts = 1000;
freqlist = 810, 13, 25<;
amplist = 81, 3, 0.5<;
sig = 0.0;
For@i = 1, i £ Length@freqlistD, i++,
sig = sig + Table@amplist@@iDD * Sin@2 * Π freqlist@@iDD * n * dtD, 8n, 1, Npts<D;
D;
sigsig = Table@8n * dt, sig@@nDD<, 8n, 1, Npts<D;
psdListPlot@sigsig, 1 dt, PlotRange ® 885, 40<, All<DD
10 15 20 25 30 35 40
0.5
1.0
5.0
10.0
50.0
100.0
Physics Pendulum Equation
[email protected] Π, 0<, 80.2, 0, 1, 1<, 0, 100, 10 000D . 8t ® Range@0, 100, 10D<
82.82743, 0.49932, -0.0862968, -0.0275841, 0.0302764, -0.0156024,
0.00583821, -0.00160537, 0.000231931, 0.0000696012, -0.0000756445<
nonlinear_oscillations.nb 5
[email protected] Π, 0<, 80.2, 0, 1, 1<, 0, 100, 10 000, PlotRange ® AllD
20 40 60 80 100t
-1
1
2
Θ
[email protected] Π, 0<, 80.2, 0, 1, 1<, 0, 100, 10 000, PlotRange ® AllD
-1 1 2Θ
-1.5
-1.0
-0.5
0.5
1.0
Θ
phasePend@80, 4.5<, 80.2, 0, 1, 1<, 0, 100, 10 000, PlotRange ® AllD
2 4 6 8 10 12 14Θ
-1
1
2
3
4
Θ
6 nonlinear_oscillations.nb
plotlist = phasePend@80, ð<, 80, 0, 1.5, 1<, -17, 17, 50 000,
PlotRange ® 88-3 Π, 3 Π<, 8-5, 5<<, AspectRatio ® 0.5D & Range@-5, 5, 0.5D;
Show@plotlistD
-5 5Θ
-4
-2
2
4
Θ
plotlist = phasePend@80, ð<, 80.4, 0, 1.5, 1<, -17, 17, 50 000,
PlotRange ® 88-3 Π, 3 Π<, 8-5, 5<<, AspectRatio ® 0.5D & Range@-5, 5, 0.5D;
Show@plotlistD
-5 5Θ
-4
-2
2
4
Θ
nonlinear_oscillations.nb 7
dt = 0.1; tstart = 0; tend = 2000;
angledata1 = [email protected] Π, 0<, 80, 0, 2 Π, 1<, tstart, tend, 200 000D .
8t ® Range@tstart, tend, dtD<;
angledata2 = 1000 * [email protected] Π, 0<, 80, 0, 2 Π, 1<, tstart, tend, 200 000D .
8t ® Range@tstart, tend, dtD<;
f1 = psdListPlot@angledata1, 1 dt, PlotRange ® 880, 4<, 80.0001, 1000<<, Joined ® TrueD;
f2 = psdListPlot@angledata2, 1 dt,
PlotRange ® 880, 4<, 80.0001, 1000<<, PlotStyle ® Red, Joined ® TrueD;
ShowBf1, f2, AxesLabel ® :"f", "cts Hz ">F
0 1 2 3 4f10-4
0.01
1
100
cts Hz
pt1 = anglePend@80, ð Π<, 80.5, 1, 1, 2 3<, 0, 50, 10 000, PlotStyle -> [email protected] * ðD,
Ticks ® 8Π Range@0, 6, 1D, Automatic<,
AspectRatio ® 0.5, PlotRange ® AllD & 81 2, 3 2, 2, 3<;
Show@pt1D
Π 2 Π 3 Π 4 Π 5 Π 6 Πt
5
10
15
20
Θ
8 nonlinear_oscillations.nb
pt2 = phasePend@80, ð Π<, 80.5, 1, 1, 2 3<, 0, 400, 50 000,
AspectRatio ® 0.5, PlotStyle -> [email protected] * ðD,
Ticks ® 8Π Range@0, 6, 1D, Automatic<, PlotRange ® 88-3 Π, 7 Π<, 8-3, 9<<D & 81 2, 3 2, 2, 3<;
Show@pt2D
Π 2 Π 3 Π 4 Π 5 Π 6 ΠΘ
-2
2
4
6
8
Θ
pt3 = poincarePend@80, ð Π<, 80.5, 1, 1, 2 3<, 123, 400, 50 000,
AspectRatio ® 0.5, Ticks ® 8Π Range@0, 6, 1D, Automatic<,
PlotRange ® 88-3 Π, 7 Π<, 8-3, 9<<D & 81 2, 3 2, 2, 3<;
Show@pt3D
Π 2 Π 3 Π 4 Π 5 Π 6 ΠΘ
-2
2
4
6
8
Θ
nonlinear_oscillations.nb 9
pt4 = anglePend@8Π 2, 0<, 80.2, ð, 0.694< Flatten, 0, 500, 20 000,
Ticks ® 8Automatic, Π Range@-1, 10, 1 4D<, PlotStyle -> [email protected] * ðD,
PlotPoints ® 150, AspectRatio ® 0.3,
PlotRange ® AllD & 880, 1<, 80.1, 1<, 80.3, 1<<;
pt5 = anglePend@8Π 2, 0<, 80.2, ð, 0.694< Flatten, 0, 1000, 20 000,
Ticks ® 8Automatic, Π Range@-10, 10, 2D<, PlotStyle -> Hue@2 * ðD,
PlotPoints ® 150, AspectRatio ® 0.2,
PlotRange ® AllD & 880.69, 1<, 80.74, 1<, 80.83, 1<<;
Show@pt4DShow@pt5D
100 200 300 400 500t
-Π
4
Π
4
Π
2
Θ
200 400 600 800 1000t
-10 Π-8 Π-6 Π-4 Π
2 Π4 Π6 Π8 Π
Θ
10 nonlinear_oscillations.nb
pt6 = phasePend@8Π 2, 0<, 80.2, ð, 0.694< Flatten, 0, 500, 20 000,
Ticks ® 8Π Range@-10, 10, 1 4D, Automatic<, PlotStyle -> [email protected] * ðD,
PlotRange ® All
D & 880, 1<, 80.1, 1<, 80.3, 1<<;
pt7 = phasePend@8Π 2, 0<, 80.2, ð, 0.694< Flatten, 0, 1000, 20 000,
Ticks ® 8Π Range@-10, 10, 1D, Automatic<, PlotStyle -> Hue@2 * ðD,
AspectRatio ® 0.5, PlotRange ® All
D & 880.69, 1<<;
pt8 = phasePend@8Π 2, 0<, 80.2, ð, 0.694< Flatten, 0, 1000, 20 000,
Ticks ® 8Π Range@-10, 10, 1D, Automatic<, PlotStyle -> Hue@2 * ðD,
AspectRatio ® 0.12, PlotRange ® All
D & 880.74, 1<, 80.83, 1<<;
pt9 = phasePend@8Π 2, 0<, 80.2, ð, 0.694< Flatten, 0, 1000, 20 000,
PlotStyle -> Hue@2 * ðD, AspectRatio ® 0.12, PlotRange ® All
D & 880.982, 1<<;
Show@pt6DShow@pt7DShow@pt8DShow@pt9D
-Π
4
Π
4
Π
2
Θ
-1.0
-0.5
0.5
Θ
Π 2 ΠΘ
-2
-1
1
2
Θ
-10 Π-9 Π-8 Π-7 Π-6 Π-5 Π-4 Π-3 Π-2 Π-Π Π2 Π3 Π4 Π5 Π6 Π7 ΠΘ
-3
3
Θ
-700 -600 -500 -400 -300 -200 -100Θ
-3
Θ
nonlinear_oscillations.nb 11
pt10 = phasePendw@8Π 2, 0<, 80.2, ð, 0.694< Flatten, 1000, 2000, 60 000,
Ticks ® 8Π Range@-1, 1, 1 4D, Automatic<, PlotStyle -> [email protected] * ðD,
PlotRange ® All
D & 880.1, 1<, 80.69, 1<, 80.83, 1<, 80.982, 1<<;
Show@GraphicsGrid@Partition@pt10, 2DDD
Θ
-0.10
-0.05
0.05
0.10
Θ
-Π -3 Π
4-
Π
2-
Π
4
Π
4
Π
2
3 Π
4Π
Θ
-2
-1
1
2
Θ
-Π -3 Π
4-
Π
2-
Π
4
Π
4
Π
2
3 Π
4Π
Θ
-2
-1
1
2
Θ
-Π -3 Π
4-
Π
2-
Π
4
Π
4
Π
2
3 Π
4Π
Θ
-2
-1
1
Θ
12 nonlinear_oscillations.nb
pt11 = poincarePendw@8Π 2, 0<, 80.2, ð, 0.694< Flatten, 1000, 2000, 60 000,
Ticks ® 8Π Range@-1, 1, 1 4D, Automatic<, PlotRange ® 88-Π, Π<, 8-Π, Π<<D &
880.1, 1<, 80.69, 1<, 80.83, 1<, 80.982, 1<<;
Show@GraphicsGrid@Partition@pt11, 2DDD
-Π -3 Π
4-
Π
2-
Π
4
Π
4
Π
2
3 Π
4Π
Θ
-3
-2
-1
1
2
3
Θ
-Π -3 Π
4-
Π
2-
Π
4
Π
4
Π
2
3 Π
4
-3
-2
-1
1
2
3
Θ
-Π -3 Π
4-
Π
2-
Π
4
Π
4
Π
2
3 Π
4Π
Θ
-3
-2
-1
1
2
3
Θ
-Π -3 Π
4-
Π
2-
Π
4
Π
4
Π
2
3 Π
4
-3
-2
-1
1
2
3
Θ
Duffing Equation
Undriven
[email protected], 0<, 81, 1, 0, 0, 1<, 0, 100, 10 000D . 8t ® Range@0, 100, 10D<
80.9, 0.89718, 0.888755, 0.874823, 0.855545,
0.831137, 0.801864, 0.768029, 0.729964, 0.688025, 0.642574<
nonlinear_oscillations.nb 13
posDuff@80, 0.4525<, 80.5, -0.61, 0, 0, 1<, 0, 100, 10 000, PlotRange ® AllD
20 40 60 80 100t
-0.5
0.5
x
[email protected], 0<, 80.5, -0.61, 0, 0, 1<, 0, 100, 10 000, PlotRange ® AllD
-0.5 0.5x
-0.4
-0.2
0.2
0.4
v
plotlist = phaseDuff@80, ð<, 80.5, -0.61, 0, 0, 1<, -17, 17, 50 000, PlotRange ®
88-1, 1<, 8-0.5, 0.5<<, AspectRatio ® 0.5D & Range@0, 0.4525, 0.4525 4D;
Show@plotlistD
-1.0 -0.5 0.5 1.0x
-0.4
-0.2
0.2
0.4
v
14 nonlinear_oscillations.nb
plotlist = phaseDuff@80, ð<, 80.5, 0.61, 0, 0, 1<, -17, 17, 50 000, PlotRange ®
88-1, 1<, 8-0.5, 0.5<<, AspectRatio ® 0.5D & Range@0, 0.4525, 0.4525 4D;
Show@plotlistD
-1.0 -0.5 0.5 1.0x
-0.4
-0.2
0.2
0.4
v
Table@8n 0.1, n 0.2<, 8n, 0, 5<D
880., 0.<, 80.1, 0.2<, 80.2, 0.4<, 80.3, 0.6<, 80.4, 0.8<, 80.5, 1.<<
plotlist =
phaseDuff@ð, 8-0.5, 0.61, 0, 0, 1<, 0, 20, 50 000, PlotRange ® 88-2, 2<, 8-1, 1<<,
AspectRatio ® 0.5D & Table@8n 0.1, 0<, 8n, -20, 20, 1<D;
Show@plotlistD
-2 -1 1 2x
-1.0
-0.5
0.5
1.0v
Driven
posDuff@80, 0.2<, 8-0.5, 0.61, 0.01, 0.1, 1<,
0, 500, 20 000, PlotRange ® All, AspectRatio ® 0.25D
100 200 300 400 500t
-1.5
-1.0
-0.5
0.5
1.0
1.5
x
nonlinear_oscillations.nb 15
phaseDuff@80, 0.2<, 8-0.5, 0.61, 0.01, 0.1, 1<, 0, 500, 20 000, PlotRange ® AllD
-1.5 -1.0 -0.5 0.5 1.0x
-0.5
0.5
v
ptd1 = posDuff@80, ð<, 8-0.5, 0.61, 0.01, 0.1, 1<, 0, 1500, 20 000,
PlotRange ® All, AspectRatio ® 0.2
D & 80.2, 0.2000001<;
Show@ptd1D
200 400 600 800 1000
-1.5
-1.0
-0.5
0.5
1.0
1.5
x
[email protected], -1.5<, 8-0.2, 0.1, 0, 1 4, 2<, 0, 500, 20 000, PlotRange ® AllD
100 200 300 400 500t
-3
-2
-1
1
2
3
x
16 nonlinear_oscillations.nb
[email protected], -1.5<, 8-0.2, 1, 0, 1 4, 2<, 0, 300, 20 000, PlotRange ® AllD
-2 -1 1 2x
-4
-2
2
4
v
[email protected], -1.5<, 8-0.2, 1, 0, 1 4, 2<, 0, 300, 20 000, PlotRange ® AllD
1.0 1.5 2.0 2.5x
-4
-2
2
4
v
nonlinear_oscillations.nb 17