« View all new features in
Mathematica
9
◄
previous
|
next
►
New in
Mathematica
9
›
Parametric Differential Equations
Parameter Sweeps
Model a bouncing ball dropped from 20 different heights.
In[2]:=
X
Plot[Evaluate[Table[pfun[height][t], {height, 1, 5, .2}]], {t, 0, 4}, PlotRange -> All, ImageSize -> Medium]
In[5]:=
X
Show[Plot[Evaluate@Table[pfun[s][t], {s, 1, 5, .2}], {t, 0, 4}, PlotStyle -> Lighter[Gray, .5], Epilog -> {Dashed, Line[{{2.5, 0}, {2.5, 5}}]}], Plot[pfun[h][t], {t, 0, 4}], ImageSize -> Medium]
In[1]:=
X
pfun = ParametricNDSolveValue[{y''[t] == -9.8 bounce[t], y[0] == height, y'[0] == 0, bounce[0] == 1, WhenEvent[y[t] == 0, If[Abs[y'[t]] > 10^-6, y'[t] -> -0.7 y'[t], {bounce[t], y'[t]} -> {0, 0}]]}, y, {t, 0, 10}, {height}, DiscreteVariables -> bounce];
Out[2]=
Find a height such that the ball will land at time
t
=2.5
.
In[3]:=
X
pfunt = ParametricNDSolveValue[{y''[t] == -9.8 bounce[t], y[0] == height, y'[0] == 0, bounce[0] == 1, WhenEvent[y[t] == 0, If[Abs[y'[t]] > 10^-6, y'[t] -> -0.7 y'[t], {bounce[t], y'[t]} -> {0, 0}]]}, y[2.5], {t, 0, 4}, {height}, DiscreteVariables -> bounce];
In[4]:=
X
h = s /. FindRoot[pfunt[s] == 0, {s, 3}]
Out[4]=
Out[5]=