6
$\begingroup$

I'm trying to plot the trajectory of a particle:

Vx = 741.61;
ay = 9.81;

Sx[t_] = Vx * t;
Sy[t_] = 1.5 - 1/2 * ay * t^2;
Vy[t_] = -ay * t;
Sy2[x_] = Sy[x/Vx];
Manipulate[
 Show[
  Graphics[ Arrow[{{Sx[t], Sy[t]}, {Sx[t] + Vx/10, Sy[t]}}], 
   Axes -> True, PlotRange -> {{0, 500}, {-1, 2}}, 
   AspectRatio -> Full, ImageSize -> {500, 300}], 
  Graphics[Arrow[{{Sx[t], Sy[t]}, {Sx[t], Sy[t] + Vy[t]/10}}], 
   Axes -> True, PlotRange -> {{0, 500}, {-1, 2}}, 
   AspectRatio -> Full, ImageSize -> {500, 300}],
  Plot[Sy2[x], {x, 0, Sx[0.553]}]
  ]
 , {t, 0, 0.553}]

Example

I would like the plot to be drawn as the projectile flies, but when I replace Plot[Sy2[x], {x, 0, Sx[0.553]}] with Plot[Sy2[x], {x, 0, Sx[t]}] Mathematica complains.

How can I change the range of the plot with Manipulate?

$\endgroup$
7
$\begingroup$

I would like the plot to be drawn as the projectile flies

You mean something like this?

enter image description here

You had few errors. Functions need to be defined using := and not =, and for initial setting, used 0.01 in Plot[sy2[x], {x, 0.01, sx[t]}] to prevent range from being zero at start, else M will complain. And few other minor issues.

Manipulate[
 Show[

  Graphics[Arrow[{{sx[t], sy[t]}, {sx[t] + vx/10, sy[t]}}],
   Axes -> True,
   PlotRange -> {{0, 500}, {-1, 2}},
   AspectRatio -> Full,
   ImageSize -> {500, 300}],

  Graphics[Arrow[{{sx[t], sy[t]}, {sx[t], sy[t] + vy[t]/10}}],
   Axes -> True,
   PlotRange -> {{0, 500}, {-1, 2}},
   AspectRatio -> Full, ImageSize -> {500, 300}],

  Plot[sy2[x], {x, 0.01, sx[t]}]
  ],
 {{t, 0, "time"}, 0, maxT, .01, Appearance -> "Labeled"},
 Initialization :>
  (
   maxT = 0.553;
   vx = 741.61;
   ay = 9.81;
   sx[t_] := vx*t;
   sy[t_] := 1.5 - 1/2*ay*t^2;
   vy[t_] := -ay*t;
   sy2[x_] := sy[x/vx]
   )
 ]
| improve this answer | |
$\endgroup$
3
$\begingroup$

Just for variety, you can exploit vectorization.

Setup:

s[vx_, vy_, t_, s0_] := {vx t, s0 + vy t - 9.81 t^2/2}
v[vx_, vy_, t_] := {{vx, 0}, {0, vy - 9.81 t}};
gnd = t /. First@Solve[Last@s[746.1, 0, t, 1.5] == 0 && t > 0, t];

Visualization:

pp[m_] := 
 With[{b = s[746.1, 0, m, 1.5], vel = v[746.1, 0, m]}, 
  ParametricPlot[Evaluate[s[746.1, 0, t, 1.5]], {t, 0, m}, 
   Epilog -> ({Arrowheads[0.05], Arrow[{b, b + 0.1 #}]} & /@ vel), 
   PlotRange -> {{0, 600}, {0, 2}}, AspectRatio -> Full]]

Manipulate[pp[time], {time, 0.01, gnd}]

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.