« View all new features in
Mathematica
9
◄
previous
|
next
►
New in
Mathematica
9
›
Advanced Hybrid and Differential Algebraic Equations
Double Pendulum
In[7]:=
X
Animate[Graphics[{{PointSize[.025], {Red, Point[{x1[t], y1[t]}]}, {Blue, Point[{x2[t], y2[t]}]}, Line[{{0, 0}, {x1[t], y1[t]}, {x2[t], y2[t]}}]} /. soldp, {Gray, Line[Map[Function[Evaluate[{x2[#], y2[#]} /. soldp]], Range[0, t, 0.025]]]}}, PlotRange -> {{-2, 2}, {-2, 0}}, Axes -> True, Ticks -> False, ImageSize -> 500], {t, 0, 10, .025}, SaveDefinitions -> True]
In[8]:=
X
With[{t = 3.7}, Graphics[{{Thick, Line[{{0, 0}, {x1[t], y1[t]}, {x2[t], y2[t]}}], PointSize[.025], {Red, Point[{x1[t], y1[t]}]}, {Blue, Point[{x2[t], y2[t]}]},} /. soldp, {Gray, Line[Map[Function[Evaluate[{x2[#], y2[#]} /. soldp]], Range[0, t, 0.025]]]}}, PlotRange -> {{-1.6, 1.6}, {-2, 0}}, Axes -> True, Ticks -> False, ImageSize -> 500]]
Play Animation
»
Stop Animation
»
Model the motion of a double pendulum in Cartesian coordinates.
X
\!\(\* GraphicsBox[{ {Thickness[0.006095368972401687], StrokeForm[{ Hue[-8.954894877446877*^-20, 1.6118810779404376`*^-17, 3.31804323410034*^-18], Opacity[1.]}], EdgeForm[{ Hue[-8.954894877446877*^-20, 1.6118810779404376`*^-17, 3.31804323410034*^-18], Opacity[1.]}], EdgeForm[None], LineBox[{{0.030479002624671986`, 0.8788604549431326}, { 0.9332567804024499, 0.8816382327209104}}]}, {StrokeForm[{ Hue[-8.954894877446877*^-20, 1.6118810779404376`*^-17, 3.31804323410034*^-18], Opacity[1.]}], EdgeForm[{ Hue[-8.954894877446877*^-20, 1.6118810779404376`*^-17, 3.31804323410034*^-18], Opacity[1.]}], EdgeForm[None], LineBox[{{0.40694444444444455`, 0.8847222222222223}, { 0.6069444444444446, 0.573611111111111}}]}, {EdgeForm[{Hue[1., 0., 0.], Opacity[1.], AbsoluteThickness[1]}], EdgeForm[None], FaceForm[{RGBColor[0.750454, 0.0792859, 0.15021], Opacity[0.65]}], DiskBox[{0.613888888888889, 0.5652777777777774}, \ {0.026388888888888906`, 0.025000000000000022`}]}, {Thickness[0.0011614486138403414`], Dashing[{Small, Small}], StrokeForm[{Hue[0., 0., 0.], Opacity[1.]}], EdgeForm[{Hue[ 0., 0., 0.], Opacity[1.]}], EdgeForm[None], LineBox[{{0.4180555555555556, 0.8791666666666668}, { 0.4180555555555556, 0.6791666666666666}}]}, {Thickness[0.0017579236139586912`], Dashing[{0, Small, 0, Small, Medium, Small}], JoinForm[{"Miter", 7.6000000000000005`}], StrokeForm[{Hue[ 0.6611111111111112, 1., 0.768518747166094], Opacity[0.92]}], EdgeForm[{Hue[0.03334096284428168, 1., 0.9486686503395132], Opacity[0.92], Thickness[0.0017579236139586912`], Dashing[{0, Small, 0, Small, Medium, Small}], JoinForm[{"Miter", 7.6000000000000005`}]}], EdgeForm[None], FaceForm[{RGBColor[0.750454, 0.0792859, 0.15021], Opacity[ 0.65]}], ArrowBox[{{0.6152777777777779, 0.5402777777777779}, { 0.6097222222222224, 0.3319444444444444}}]}, {Thickness[0.0017579236139586912`], Dashing[{0, Small, 0, Small, Medium, Small}], JoinForm[{"Miter", 7.6000000000000005`}], StrokeForm[{Hue[ 0.6777777777777777, 1., 0.9738263387429652], Opacity[0.92]}], EdgeForm[{Hue[0.03334096284428168, 1., 0.9486686503395132], Opacity[0.92], Thickness[0.0017579236139586912`], Dashing[{0, Small, 0, Small, Medium, Small}], JoinForm[{"Miter", 7.6000000000000005`}]}], EdgeForm[None], FaceForm[{RGBColor[0.750454, 0.0792859, 0.15021], Opacity[ 0.65]}], ArrowBox[{{0.6177724811745107, 0.5628337982981814}, { 0.4973911257392616, 0.7419932657534577}}]}, {Thickness[0.006531305526474716], Dashing[{Small, Small}], StrokeForm[{Hue[0., 0., 0.], Opacity[1.]}], EdgeForm[{Hue[ 0., 0., 0.], Opacity[1.]}], EdgeForm[None], LineBox[{{0.6180555555555557, 0.5625000000000001}, { 0.9680555555555558, 0.3319444444444445}}]}, {EdgeForm[{Hue[1., 0., 0.], Opacity[1.], AbsoluteThickness[1]}], EdgeForm[None], FaceForm[{RGBColor[0.750454, 0.0792859, 0.15021], Opacity[0.65]}], DiskBox[{0.9666666666666669, 0.33333333333333337`}, \ {0.026388888888889017`, 0.025000000000000022`}]}, {Thickness[0.0017579236139586912`], Dashing[{0, Small, 0, Small, Medium, Small}], JoinForm[{"Miter", 7.6000000000000005`}], StrokeForm[{Hue[ 0.6611111111111112, 1., 0.768518747166094], Opacity[0.92]}], EdgeForm[{Hue[0.03334096284428168, 1., 0.9486686503395132], Opacity[0.92], Thickness[0.0017579236139586912`], Dashing[{0, Small, 0, Small, Medium, Small}], JoinForm[{"Miter", 7.6000000000000005`}]}], EdgeForm[None], FaceForm[{RGBColor[0.750454, 0.0792859, 0.15021], Opacity[ 0.65]}], ArrowBox[{{0.9690297770407272, 0.351388888888889}, { 0.9634742214851717, 0.1430555555555555}}]}, {Thickness[0.0017579236139586912`], Dashing[{0, Small, 0, Small, Medium, Small}], JoinForm[{"Miter", 7.6000000000000005`}], StrokeForm[{GrayLevel[ 0.], Opacity[0.92]}], EdgeForm[{Hue[ 0.6611123826962692, 1., 0.7685206378271153], Opacity[0.92], Thickness[0.0017579236139586912`], Dashing[{0, Small, 0, Small, Medium, Small}], JoinForm[{"Miter", 7.6000000000000005`}]}], EdgeForm[None], FaceForm[{RGBColor[0.750454, 0.0792859, 0.15021], Opacity[ 0.65]}], ArrowBox[{{0.9708333333333334, 0.33715277777777786`}, { 0.9708333333333334, 0.46840277777777783`}}]}, {Thickness[0.0017579236139586912`], Dashing[{0, Small, 0, Small, Medium, Small}], JoinForm[{"Miter", 7.6000000000000005`}], StrokeForm[{GrayLevel[ 0.], Opacity[0.92]}], EdgeForm[{Hue[ 0.6611123826962692, 1., 0.7685206378271153], Opacity[0.92], Thickness[0.0017579236139586912`], Dashing[{0, Small, 0, Small, Medium, Small}], JoinForm[{"Miter", 7.6000000000000005`}]}], EdgeForm[None], FaceForm[{RGBColor[0.750454, 0.0792859, 0.15021], Opacity[ 0.65]}], ArrowBox[{{0.9763888888888892, 0.3291666666666667}, { 0.7680555555555559, 0.3291666666666667}}]}, {Thickness[0.0017579236139586912`], Dashing[{0, Small, 0, Small, Medium, Small}], JoinForm[{"Miter", 7.6000000000000005`}], StrokeForm[{Hue[ 0.6611111111111112, 1., 0.768518747166094], Opacity[0.92]}], EdgeForm[{Hue[0.6611123826962692, 1., 0.7685206378271153], Opacity[0.92], Thickness[0.0017579236139586912`], Dashing[{0, Small, 0, Small, Medium, Small}], JoinForm[{"Miter", 7.6000000000000005`}]}], EdgeForm[None], FaceForm[{RGBColor[0.750454, 0.0792859, 0.15021], Opacity[ 0.65]}], ArrowBox[{{0.9652777777777779, 0.33472222222222225`}, { 0.776388888888889, 0.45972222222222225`}}]}, {Thickness[0.0017579236139586912`], Dashing[{0, Small, 0, Small, Medium, Small}], JoinForm[{"Miter", 7.6000000000000005`}], StrokeForm[{GrayLevel[ 0.], Opacity[0.92]}], EdgeForm[{Hue[ 0.6611123826962692, 1., 0.7685206378271153], Opacity[0.92], Thickness[0.0017579236139586912`], Dashing[{0, Small, 0, Small, Medium, Small}], JoinForm[{"Miter", 7.6000000000000005`}]}], EdgeForm[None], FaceForm[{RGBColor[0.750454, 0.0792859, 0.15021], Opacity[ 0.65]}], ArrowBox[{{0.6152777777777779, 0.5628406708595387}, { 0.6152777777777779, 0.7461740041928719}}]}, {Thickness[0.0017579236139586912`], Dashing[{0, Small, 0, Small, Medium, Small}], JoinForm[{"Miter", 7.6000000000000005`}], StrokeForm[{GrayLevel[ 0.], Opacity[0.92]}], EdgeForm[{Hue[ 0.6611123826962692, 1., 0.7685206378271153], Opacity[0.92], Thickness[0.0017579236139586912`], Dashing[{0, Small, 0, Small, Medium, Small}], JoinForm[{"Miter", 7.6000000000000005`}]}], EdgeForm[None], FaceForm[{RGBColor[0.750454, 0.0792859, 0.15021], Opacity[ 0.65]}], ArrowBox[{{0.6153867102396515, 0.5625000000000001}, { 0.48739106753812644`, 0.5625000000000001}}]}, {Thickness[0.0010839269140212027`], Dashing[{Small, Small}], StrokeForm[{Hue[0., 0., 0.], Opacity[1.]}], EdgeForm[{Hue[ 0., 0., 0.], Opacity[1.]}], EdgeForm[None], LineBox[{{0.7875000000000002, 0.4625}, {0.9736111111111113, 0.4625}}]}, {Thickness[0.0010839269140212027`], Dashing[{Small, Small}], StrokeForm[{Hue[0., 0., 0.], Opacity[1.]}], EdgeForm[{Hue[ 0., 0., 0.], Opacity[1.]}], EdgeForm[None], LineBox[{{0.776388888888889, 0.3319444444444445}, { 0.776388888888889, 0.4458333333333334}}]}, {Thickness[0.0010839269140212027`], Dashing[{Small, Small}], StrokeForm[{Hue[0., 0., 0.], Opacity[1.]}], EdgeForm[{Hue[ 0., 0., 0.], Opacity[1.]}], EdgeForm[None], LineBox[{{0.49583333333333357`, 0.7458333333333335}, { 0.6152777777777779, 0.7458333333333335}}]}, {Thickness[0.0010839269140212027`], Dashing[{Small, Small}], StrokeForm[{Hue[0., 0., 0.], Opacity[1.]}], EdgeForm[{Hue[ 0., 0., 0.], Opacity[1.]}], EdgeForm[None], LineBox[{{0.49027777777777803`, 0.7347222222222224}, { 0.49027777777777803`, 0.5652777777777779}}]}, InsetBox[ StyleBox[ TagBox[ RowBox[{ SubscriptBox["m", "2"], "g"}], "RawBoxes"], FontSize->14, Magnification->1.25, Background->GrayLevel[ 1.]], {0.9819444444444447, 0.12361111111111112`}, { Left, Baseline}, Alignment->{Left, Top}], InsetBox[ StyleBox[ TagBox[ RowBox[{ SubscriptBox["m", "1"], "g"}], "RawBoxes"], FontSize->14, Magnification->1.25, Background->GrayLevel[ 1.]], {0.5177055993000876, 0.3296478565179357}, { Left, Baseline}, Alignment->{Left, Top}], InsetBox[ StyleBox[ TagBox[ SubscriptBox["\[Lambda]", "1"], "RawBoxes"], FontSize->14, Magnification->1.25, Background->GrayLevel[ 1.]], {0.5597222222222223, 0.6569444444444444}, { Left, Baseline}, Alignment->{Left, Top}], InsetBox[ StyleBox[Subscript[\[Lambda], 2], Magnification->1.25, Background->GrayLevel[ 1.]], {0.8930555555555557, 0.4013888888888889}, { Left, Baseline}, Alignment->{Left, Top}], InsetBox[ StyleBox[ TagBox[ RowBox[{ RowBox[{ SubscriptBox["\[Lambda]", "2"], "Cos", " ", SubscriptBox["\[Theta]", "2"]}], " ", "=", " ", RowBox[{ FractionBox[ SubscriptBox["\[Lambda]", "2"], SubscriptBox["l", "2"]], RowBox[{"(", RowBox[{ SubscriptBox["y", "2"], "-", SubscriptBox["y", "1"]}], ")"}]}]}], "RawBoxes"], Magnification->1.25, Background->GrayLevel[ 1.]], {0.9143153980752408, 0.5200896762904642}, { Left, Baseline}, Alignment->{Left, Top}], InsetBox[ StyleBox[ TagBox[ RowBox[{ RowBox[{ SubscriptBox["\[Lambda]", "2"], "Sin", " ", "\[Theta]"}], " ", "=", " ", RowBox[{ FractionBox[ SubscriptBox["\[Lambda]", "2"], SubscriptBox["l", "2"]], RowBox[{"(", RowBox[{ SubscriptBox["x", "2"], "-", SubscriptBox["x", "1"]}], ")"}]}]}], "RawBoxes"], Magnification->1.25, Background->GrayLevel[ 1.]], {0.6246719160104987, 0.2506561679790035}, { Left, Baseline}, Alignment->{Left, Top}], InsetBox[ StyleBox[ TagBox[ RowBox[{ RowBox[{ SubscriptBox["\[Lambda]", "1"], "Cos", " ", SubscriptBox["\[Theta]", "1"]}], "=", RowBox[{ FractionBox[ SubscriptBox["\[Lambda]", "1"], SubscriptBox["l", "1"]], SubscriptBox["y", "1"]}]}], "RawBoxes"], Magnification->1.25, Background->GrayLevel[1.]], {0.6482939632545932, 0.746719160104987}, { Left, Baseline}, Alignment->{Left, Top}], InsetBox[ StyleBox[ TagBox[ RowBox[{ RowBox[{ SubscriptBox["\[Lambda]", "1"], "Sin", " ", SubscriptBox["\[Theta]", "1"]}], "=", RowBox[{ FractionBox[ SubscriptBox["\[Lambda]", "1"], SubscriptBox["l", "1"]], SubscriptBox["x", "1"]}]}], "RawBoxes"], Magnification->1.25, Background->GrayLevel[ 1.]], {0.22834645669291342`, 0.5472440944881893}, { Left, Baseline}, Alignment->{Left, Top}], InsetBox[ StyleBox[ TagBox[ SubscriptBox["\[Theta]", "1"], "RawBoxes"], Magnification->1.25, Background->GrayLevel[1.]], {0.4383202099737533, 0.757217847769029}, { Left, Baseline}, Alignment->{Left, Top}], InsetBox[ StyleBox[ TagBox[ SubscriptBox["\[Theta]", "2"], "RawBoxes"], Magnification->1.25, Background->GrayLevel[ 1.]], {0.6377952755905512, 0.4816272965879269}, { Left, Baseline}, Alignment->{Left, Top}], InsetBox[ StyleBox[ TagBox[ RowBox[{"(", RowBox[{ SubscriptBox["x", "1"], ",", SubscriptBox["y", "1"]}], ")"}], "RawBoxes"], Magnification->1.25, Background->GrayLevel[ 1.]], {0.6666666666666667, 0.5682414698162731}, { Left, Baseline}, Alignment->{Left, Top}], InsetBox[ StyleBox[ TagBox[ RowBox[{"(", RowBox[{ SubscriptBox["x", "2"], ",", SubscriptBox["y", "2"]}], ")"}], "RawBoxes"], Magnification->1.25, Background->GrayLevel[ 1.]], {1.0157480314960632`, 0.32152230971128615`}, { Left, Baseline}, Alignment->{Left, Top}], InsetBox[ StyleBox[ TagBox[ RowBox[{"(", RowBox[{"0", ",", "0"}], ")"}], "RawBoxes"], Magnification->1.25, Background->GrayLevel[ 1.]], {0.3858267716535434, 0.9120734908136484}, { Left, Baseline}, Alignment->{Left, Top}]}, ContentSelectable->True, ImagePadding->{{0., 0.}, {0., 0.}}, ImageSize->{509., 381.}, PlotRange->{{0., 1.3333333333333335`}, {0., 1.}}, PlotRangePadding->Automatic]\)
Derive the governing equations using Newton's second law of motion,
and
.
In[1]:=
X
deqns = {Subscript[m, 1] x1''[t] == (\[Lambda]1[t]/Subscript[l, 1]) x1[ t] - (\[Lambda]2[t]/Subscript[l, 2]) (x2[t] - x1[t]), Subscript[m, 1] y1''[t] == (\[Lambda]1[t]/Subscript[l, 1]) y1[ t] - (\[Lambda]2[t]/Subscript[l, 2]) (y2[t] - y1[t]) - Subscript[m, 1] g, Subscript[m, 2] x2''[t] == (\[Lambda]2[t]/Subscript[l, 2]) (x2[t] - x1[t]), Subscript[m, 2] y2''[t] == (\[Lambda]2[t]/Subscript[l, 2]) (y2[t] - y1[t]) - Subscript[m, 2] g};
The lengths of the pendulum rods are fixed. These are expressed as algebraic constraints.
In[2]:=
X
aeqns = {x1[t]^2 + y1[t]^2 == Subscript[l, 1]^2, (x2[t] - x1[t])^2 + (y2[t] - y1[t])^2 == Subscript[l, 2]^2};
Specify the initial state of the system as initial conditions.
In[3]:=
X
ics = {x1[0] == 1, y1[0] == 0, x1'[0] == 0, y1'[0] == 0, x2[0] == 1, y2[0] == -1, x2'[0] == 0, y2'[0] == 0};
Specify the physical parameters for the pendulum system.
In[4]:=
X
params = {g -> 9.81, Subscript[m, 1] -> 1, Subscript[m, 2] -> 1, Subscript[l, 1] -> 1, Subscript[l, 2] -> 1};
Solve and visualize the system.
In[5]:=
X
soldp = First[ NDSolve[{deqns, aeqns, ics} /. params, {x1, y1, x2, y2, \[Lambda]1, \[Lambda]2}, {t, 0, 15}, Method -> {"IndexReduction" -> {Automatic, "IndexGoal" -> 0}}]];
In[6]:=
X
ParametricPlot[ Evaluate[{{x1[t], y1[t]}, {x2[t], y2[t]}} /. soldp], {t, 0, 15}, PlotStyle -> {Red, Blue}, ImageSize -> Medium, PlotLegends -> {"Trajectory of pendulum 1", "Trajectory of pendulum 2"}]
Out[6]=