RosettaCodeData/Task/Animate-a-pendulum/Mathematica/animate-a-pendulum.math

28 lines
418 B
Plaintext

tmax = 10;
g = 9.8;
l = 1;
pendulum = Module[
{g, l},
ParametricNDSolve[
{
y''[t] + g/l Sin[y[t]] == 0,
y[0] == 0, y'[0] == 1
},
{y},
{t, 0, tmax},
{g, l}
]
];
Animate[
Graphics[
Rotate[
{Line[{{0, 0}, {0, -1}}], Disk[{0, -1}, .1]},
Evaluate[y[g, l] /. pendulum][t],
{0, 0}
],
PlotRange -> {{-l, l}, {-l - .5, 0}}
],
{t, 0, tmax},
AnimationRate -> 1
]