« View all new features in
Mathematica
9
◄
previous
|
next
►
New in
Mathematica
9
›
Advanced Hybrid and Differential Algebraic Equations
Bouncing Balls
In[2]:=
X
kin[v_] := .5 v^2; pot[y_] := 9.8 y; energy[y_, v_] := kin[v] + pot[y]; GraphicsGrid[{{Plot[y[t] /. ball, {t, 0, 10}, AxesLabel -> {"t", "y"}], Plot[Evaluate[{kin[y'[t]], pot[y[t]], energy[y[t], y'[t]]} /. ball], {t, 0, 10}, Filling -> {3 -> 0}, AxesLabel -> {"t", "energy"}]}}]
In[4]:=
X
GraphicsGrid[{{Show[ ParametricPlot[ Evaluate[{{x[t], y[t]}, {x[t], a[t]}} /. ballsteps], {t, 0, 15}, ImageSize -> 300, Epilog -> {Red, PointSize[Medium], Point[points]}], Plot[{0, Floor[6 - x]}, {x, -1, 15}, Filling -> {2 -> 0}, Exclusions -> None], Frame -> {{True, False}, {True, False}}, FrameLabel -> {"x", "y"}], Plot[Evaluate[{kin[y'[t]], pot[y[t]], energy[y[t], Norm[{x'[t], y'[t]}]]} /. ballsteps], {t, 0, 15}, Filling -> {3 -> 0}, Frame -> {{True, False}, {True, False}}, FrameLabel -> {"t", "energy"}, Ticks -> None]}}]
Model a bouncing ball and plot its total, kinetic, and potential energy.
In[1]:=
X
ball = NDSolve[{y''[t] == -9.81, y[0] == 13.5, y'[0] == 0, WhenEvent[y[t] == 0, y'[t] -> -0.95 y'[t]]}, y, {t, 0, 10}];
Out[2]=
Model a ball bouncing down steps and plot its total, kinetic, and potential energy.
In[3]:=
X
{ballsteps, {points}} = NDSolve[{x''[t] == 0, y''[t] == -9.8, y[0] == 6, y'[0] == 0, x[0] == 0, x'[0] == 1, a[0] == 5, WhenEvent[Mod[x[t], 1] == 0, If[a[t] > 0, a[t] -> a[t] - 1, "RemoveEvent"]], WhenEvent[ y[t] == a[t], {{x'[t], y'[t]} -> .9 {x'[t], -y'[t]}, Sow[{x[t], y[t]}]}]}, {x, y, a}, {t, 0, 15}, DiscreteVariables -> {a}] // Reap;
Out[4]=