3
$\begingroup$

I just need a list of numerical solutions for x[t], x'[t], x''[t]. While I know how to graph them, I have no idea how to get solutions into a table. Can someone please help?

g = 9.81;
v = 20;
θ = Pi/4;
k1 = 0.2;

sol1 = 
  NDSolve[
    {x''[t] == -k1 x'[t]  Sqrt[y'[t]^2 + x'[t]^2], 
     y''[t] == -k1  y'[t]  Sqrt[y'[t]^2 + x'[t]^2] - g m, 
     x[0] == 0, y[0] == 0, x'[0] == v Cos[θ], y'[0] == v Sin[θ]}, 
    {x, y}, {t,0, 10}];

tkoncni = t /. FindRoot[y[t] /. sol1, {t, 1}];

gr11 = 
  Plot[y[t] /. sol1, {t, 0, tkoncni}, 
    PlotRange -> Automatic, AxesLabel -> {"t", "y(t)"}];

gr12 = 
  ParametricPlot[{x[t] /. sol1[[1]], y[t] /. sol1}, {t, 0, tkoncni}, 
    PlotRange -> Automatic, AxesLabel -> {"x(t)", "y(t)"}];
$\endgroup$
2
  • 3
    $\begingroup$ can't you use Table or so? $\endgroup$
    – Wjx
    Commented Jul 7, 2016 at 8:27
  • $\begingroup$ i know i have to use table, i just dont know how to use it correctly $\endgroup$
    – iCEEwiener
    Commented Jul 7, 2016 at 10:21

1 Answer 1

2
$\begingroup$

The easy way to do it IMO is to extract the interpolating functions from your solution.

g = 9.81;
v = 20;
θ = Pi/4;
k1 = 0.2;
m = 1.;

sol1 =
  NDSolve[
   {x''[t] == -k1 x'[t] Sqrt[y'[t]^2 + x'[t]^2], 
    y''[t] == -k1 y'[t] Sqrt[y'[t]^2 + x'[t]^2] - g m, 
    x[0] == 0, y[0] == 0, x'[0] == v Cos[θ], y'[0] == v Sin[θ]}, 
   {x, y}, {t, 0, 10}]

{xF, yF} = sol1[[1, All, 2]];
tmax = t /. FindRoot[yF[t], {t, 1}]

1.58915

Table[{xF[t], xF'[t], xF''[t]}, {t, Subdivide[tmax, 10]}]
{{0., 14.1421, -56.5685}, {1.74666, 8.75671, -20.1819}, 
 {2.93728, 6.49064, -10.0301}, {3.8629, 5.26585, -5.92728}, 
 {4.63437, 4.49283, -4.04329}, {5.30152, 3.92479, -3.23141}, 
 {5.88598, 3.43832, -2.9428}, {6.39581, 2.9813, -2.81483}, 
 {6.83461, 2.54532, -2.66073}, {7.20639, 2.13967, -2.43278}, 
 {7.51685, 1.77504, -2.14991}}
Table[{yF[t], yF'[t], yF''[t]}, {t, Subdivide[tmax, 10]}]
{{0., 14.1421, -66.3785}, {1.64027, 7.49102, -27.0749}, 
 {2.54638,   4.19187, -16.2878}, {3.02848, 1.98633, -12.0458}, 
 {3.2019, 0.248938, -10.034}, {3.12038, -1.24218, -8.78726}, 
 {2.8168, -2.54778, -7.62941}, {2.32084, -3.66031, -6.35408}, 
 {1.6645, -4.56506, -5.03796}, {0.880709, -5.26691, -3.82158}, 
 {-4.16334*10^-16, -5.78996, -2.79726}}
$\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.