2
$\begingroup$

The soluton of this differential equation describes the trajectory of a particle considering the air resistance. Im wondering if anyone has a good way plot the solution in 2D.

enter image description here

       Clear[t]
solx = DSolve[{x''[t] + k x'[t] == 0, x[0] == 0, 
     x'[0] == v0 Cos[theta]}, x[t], t][[1, 1, 2]] // Simplify
soly = DSolve[{u''[t] + k u'[t] == -g, u'[0] == v0 Sin[theta], 
     u[0] == 0}, u[t], t][[1, 1, 2]] // Simplify
v0=10;(*m/s*)
k=1.;
theta=Pi/4;

EDIT

Just as a curiosity, an animation of the range in function of the angle:

Clear[t,theta]
g = 9.81;
Manipulate[ParametricPlot[{solx, soly} /. t -> tt /. theta -> \[Theta], {tt, 0, 1.8}, PlotRange -> {{0, 6}, {0, 5}}], {\[Theta], Pi/10, Pi/2}]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ ParametricPlot[{solx, soly} /. g -> 9.8, {t, 0, 1}, AspectRatio -> 1]. $\endgroup$
    – march
    Dec 16, 2015 at 19:46

1 Answer 1

5
$\begingroup$
v0 = 10;
k = 1.;
theta = Pi/4;
g = 10;
solx = DSolve[{x''[t] + k x'[t] == 0, x[0] == 0, x'[0] == v0 Cos[theta]}, x[t], t]
soly = DSolve[{u''[t] + k u'[t] == -g, u'[0] == v0 Sin[theta], u[0] == 0}, u[t], t]
ParametricPlot[{x[t], u[t]} /. solx /. soly, {t, 0, 1}]

Mathematica graphics

To plot until it comes down to earth:

tf = t /. First@Solve[(u[t] /. soly) == 0 && t > .1, t]
ParametricPlot[{x[t], u[t]} /. solx /. soly, {t, 0, tf}]

Mathematica graphics


Here you have the same, done with the vectorial form of NDSolve[ ]

th = Pi/4;
k = 1.;
v0 = 10;
s = {0, -g};
ds = NDSolveValue[
  {w'[t] == {0, 0}, w[0] == {0, -g},
   r''[t] + k r'[t] == w[t], r[0] == {0, 0}, r'[0] == v0 {Cos@th, Sin@th},
   WhenEvent[Last[r[t]] == 0, (tf = t; "StopIntegration")]},
  {r, w}, {t, 0, 10}]

ParametricPlot[Through[ds[t]][[1]], {t, 0, tf}]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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