Created
May 18, 2014 06:13
-
-
Save BrianWeinstein/b7317c5e4f56a9a12cdb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x1[t_] := R1*Sin[\[Theta]1[t]] | |
y1[t_] := (-R1)*Cos[\[Theta]1[t]] | |
x2[t_] := R1*Sin[\[Theta]1[t]] + R2*Sin[\[Theta]2[t]] | |
y2[t_] := (-R1)*Cos[\[Theta]1[t]] - R2*Cos[\[Theta]2[t]] | |
v1[t_] := Sqrt[D[x1[t], t]^2 + D[y1[t], t]^2] | |
v2[t_] := Sqrt[D[x2[t], t]^2 + D[y2[t], t]^2] | |
T1[t_] := (1/2)*m1*v1[t]^2 | |
T2[t_] := (1/2)*m2*v2[t]^2 | |
U[t_] := m1*g*y1[t] + m2*g*y2[t] | |
L[t_] := T1[t] + T2[t] - U[t] | |
Simplify[D[LB[t], \[Theta]1B[t]] == D[D[LB[t], Derivative[1][\[Theta]1B][t]], t]]; | |
Simplify[D[LB[t], \[Theta]2B[t]] == D[D[LB[t], Derivative[1][\[Theta]2B][t]], t]]; | |
\[Theta]10 = Pi/2; | |
\[Theta]1d0 = 0; | |
\[Theta]20 = Pi/2; | |
\[Theta]2d0 = 0; | |
g = 9.8; | |
R1 = 0.7; | |
R2 = 0.7; | |
m1 = 1; | |
m2 = 1; | |
sols = | |
NDSolve[ | |
{R1*(g*m1*Sin[\[Theta]1[t]] + g*m2*Sin[\[Theta]1[t]] + | |
m2*R2*Sin[\[Theta]1[t] - \[Theta]2[t]]*Derivative[1][\[Theta]2][t]^2 + | |
(m1 + m2)*R1*Derivative[2][\[Theta]1][t] + | |
m2*R2*Cos[\[Theta]1[t] - \[Theta]2[t]]*Derivative[2][\[Theta]2][t]) == 0, | |
m2*R2*(g*Sin[\[Theta]2[t]] - R1*Sin[\[Theta]1[t] - | |
\[Theta]2[t]]*Derivative[1][\[Theta]1][t]^2 + R1*Cos[\[Theta]1[t] - | |
\[Theta]2[t]]*Derivative[2][\[Theta]1][t] + R2*Derivative[2][\[Theta]2][t]) == 0, | |
\[Theta]1[0] == \[Theta]10, | |
Derivative[1][\[Theta]1][0] == \[Theta]1d0, | |
\[Theta]2[0] == \[Theta]20, | |
Derivative[1][\[Theta]2][0] == \[Theta]2d0 | |
}, | |
{\[Theta]1, Derivative[1][\[Theta]1], Derivative[2][\[Theta]1], | |
\[Theta]2, Derivative[1][\[Theta]2], Derivative[2][\[Theta]2] | |
}, | |
{t, 0, 490}, | |
MaxSteps -> 100000 | |
]; | |
\[Theta]1n[t_] := Evaluate[\[Theta]1[t] /. sols[[1,1]]] | |
\[Theta]2n[t_] := Evaluate[\[Theta]2[t] /. sols[[1,4]]] | |
\[Theta]d1n[t_] := Evaluate[Derivative[1][\[Theta]1][t] /. sols[[1,1]]] | |
\[Theta]d2n[t_] := Evaluate[Derivative[1][\[Theta]2][t] /. sols[[1,4]]] | |
x1n[t_] := R1*Sin[\[Theta]1n[t]] | |
y1n[t_] := (-R1)*Cos[\[Theta]1n[t]] | |
x2n[t_] := R1*Sin[\[Theta]1n[t]] + R2*Sin[\[Theta]2n[t]] | |
y2n[t_] := (-R1)*Cos[\[Theta]1n[t]] - R2*Cos[\[Theta]2n[t]] | |
Manipulate[ | |
Show[ | |
ParametricPlot[ | |
{{x1n[t], y1n[t]}, {x2n[t], y2n[t]}}, | |
{t, 0, tf}, | |
PlotStyle -> {{Red}, {Blue}}, | |
AspectRatio -> Automatic, | |
PlotRange -> {{-R1 - R2, R1 + R2}, {-R1 - R2, (R1 + R2)/3.5}}, | |
Axes -> True, | |
GridLines -> Automatic, GridLinesStyle -> Directive[LightGray] | |
], | |
Graphics[ | |
{ | |
{AbsoluteThickness[2], Red, Line[{{0, 0}, {x1n[tf], y1n[tf]}}]}, | |
{AbsoluteThickness[2], Blue, Line[{{x1n[tf], y1n[tf]}, {x2n[tf], y2n[tf]}}]}, | |
{PointSize[Large], Red, Point[{x1n[tf], y1n[tf]}]}, | |
{PointSize[Large], Blue, Point[{x2n[tf], y2n[tf]}]} | |
} | |
] | |
], | |
{tf, 0.01, 14, 0.1} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment