I keep getting funny errors when trying to do this:
g[t_] := -9.8;
a[t_] := Piecewise[{{0, t < 0}, {12, 0 <= t < 1}, {14,
1 <= t < 3}, {11, 3 <= t < 8}, {0, t >= 8}}];
Plot[a[t], {t, 0, 10}]
v[t_] := Integrate[a[t], t];
v[t]
Integrate[a[t], t]
Plot[v[t], {t, 0, 10}]
Plot[g[t], {t, 0, 10}]
mfroeling
(Martijn Froeling)
February 6, 2022, 6:28pm
2
When you definve v[t_]:=Integrate [f[t],t] and you try to plot it you are basically solving for each t
Plot[{
Integrate[f[0],0]
Integrate[f[1],1]
Integrate[f[2],2]
...
}]
That won’t work, so first calculate the integral and then define a function that replaces after integration.
vt = Integrate[a[t], t]
v[ti_] := vt /. t -> ti
Plot[v[t], {t, 0, 10}]
Thank you very much!! I don’t know how I could have divined this from the documentation. What is the last line (117 Ture) trying to tell me?
I would now like to integrate v[t]. Do I proceed in the same way?`
g[t_] := -9.8;
a[t_] := Piecewise[{{0, t < 0}, {12, 0 <= t < 1}, {25,
1 <= t < 3}, {11, 3 <= t < 8}, {0, t >= 8}}];
Plot[a[t], {t, 0, 10}]
v1 = Integrate[a[t], t];
v2[tj_] := v1 /. t -> tj
v2[t]
Plot[v2[t], {t, -1, 10}]
vt = Integrate[a[t], t];
v[ti_] := vt /. t -> ti;
v[t]
Plot [v[t], {t, 0, 10}]
Plot[g[t], {t, 0, 10}]
Hi Orest,
An alternative to Martijn’s answer
(* Acceleration *)
a[t_] :=
Piecewise[{{0, t < 0}, {12, 0 <= t < 1}, {25, 1 <= t < 3}, {11, 3 <= t < 8}, {0, t >= 8}}]
(* Velocity *)
v[t_] := Integrate[a[t], t];
(* Distance *)
s[t_] := Integrate[v[t], t];
Plot[Evaluate[{a[t], v[t], s[t]}], {t, 0, 10},
PlotTheme -> "Detailed",
PlotRange -> All,
ImageSize -> 600]
The 117 True in the Piecewise means the value is 117 everywhere else in the domain t > 8.
I tried this first and was getting errors. Obviously, you don’t. Wonder why.
I’ll try again.
Thank you!
GOGO