I was reading basic help here How to | Combine Two or More Graphics , but I did not get it.
I have simple differential equation and want to change a constant "b" (in this case "damping") and plot all graphs in a single image. Here is the code:
(*Single mass damper system of a rail car *)
(*with 10 mm starting deflection *)
m = 40000; (* [kg] *)
k = 1600000; (* [N/m] *)
for[b=0, b<=160000, b=b+20000,
sol = NDSolve[{
m*x''[t] + b*x'[t] + k*x[t]== 0,
x'[0] == 0,x[0] == 0.01},
x[t], {t, 0, 10}];
Print[Plot[x[t] /. sol, {t, 0, 3},
PlotRange -> Full ,
PlotTheme -> {"Grid"},
AxesLabel->{"Time [s]", "Vertical suspension deflection [m]"},
PlotLabel->Style["Single mass damper system of a rail car", 12, Bold]]]
]
Can anyone please help? I'm just missing "hold on" from Matlab here. Thank you in advance.
sols=Table[x[t]/.NDSolve[{m*x''[t]+b*x'[t]+k*x[t]==0,x'[0]==0,x[0]==0.01},x[t],{t,0,10}],{b,0,160000,20000}]; Plot[sols,{t,0,3}]
$\endgroup$for
is not the same asFor
. $\endgroup$ParametricNDSolveValue
, which makes is much easier to solve DEs for different parameter values. $\endgroup$