1

In Excel I compiled some spreadsheets implementing the Runge Kutta method of the 4th order. Initially I tested with some systems of differential equations that are known to the analytical solution and the error was always the order of 10^-7 - 10^-5.

So I passed to the resolution of some of differentiable system of equations can not be solved analytically and the graphs obtained were perfectly coincident with those Wolfram Mathematica 11.0.1. It seemed to work wonders when all I had to face in the following system of differential equations:

ode1 = D[(a[s]^2 + 4a[s]^4t[s]^2)t'[s], s] - 4a[s]^4t[s]t'[s]^2 - 
         (a[s] + 8a[s]^3t[s]^2)a'[s]^2 == 0;

ode2 = D[4a[s]^2t[s]^4a'[s], s] - 4a[s]t[s]^4a'[s]^2 - 8a[s]^2t[s]^3t'[s]^2 == 0;

ic = {a[-10] == 3.03721, a'[-10] == -0.0555245, t[-10] == 1.81013, t'[-10] == -0.0608313};

sol = NDSolve[{ode1, ode2, ic}, {a, t}, {s, -10, 10}];

Plot[Evaluate[{a[s], t[s]} /. sol],
     {s, -10, 10},
     AxesLabel -> {"s", "a, t"},
     PlotLegends -> {"a[s]", "t[s]"},
     PlotRange -> {{-10, 10}, {0, 5}}]

or equivalently:

sol = NDSolve[
   {a'[s] == b[s],
    b'[s] == (-b[s]^2 t[s] - 4 a[s] b[s] u[s] + 2 a[s] u[s]^2)/(a[s] t[s]),
    t'[s] == u[s],
    u'[s] == (b[s]^2 + 8 a[s]^2 b[s]^2 t[s]^2 - 2 b[s] u[s] - 16 a[s]^2 b[s] t[s]^2 u[s] - 
              4 a[s]^3 t[s] u[s]^2)/(a[s] (1 + 4 a[s]^2 t[s]^2)),
    a[-10] == 3.03721,
    b[-10] == -0.0555245,
    t[-10] == 1.81013,
    u[-10] == -0.0608313},
   {a, b, t, u}, {s, -10, 10}];

Plot[Evaluate[{a[s], t[s]} /. sol],
     {s, -10, 10},
     AxesLabel -> {"s", "a, t"},
     PlotLegends -> {"a[s]", "t[s]"},
     PlotRange -> {{-10, 10}, {0, 5}}]

enter image description here

while in Microsoft Excel 2016 I get the following graph:

enter image description here

You might point out some strategies to check the accuracy of such graphs? How do you be certain of the graphs obtained from MMA without the possibility of an analytical feedback? It may be that there are numeric problems?

Thanks so much!

πρόσεχε
  • 4,452
  • 1
  • 12
  • 28
  • 1
    I would try to change the method and various options, and see if the solution changes. One of the easiest things to try is to see if the solution is sensitive to the MaxStepSize setting. If possible, try to do the same in Excel (does it have a similar setting)? – Szabolcs Mar 29 '17 at 09:18
  • 1
    It is also good to double check that you are really solving the same equations in the two systems. Little mistakes are too easy to overlook with such a long equation. – Szabolcs Mar 29 '17 at 09:19
  • 2
    It might interest you to know that with NDSolve[], there's often no need to convert high-order DEs into a bunch of first-order DEs. So, NDSolve[{y''[x] == -y[x], y[0] == 1, y'[0] == 0}, y, {x, 0, Pi}] works directly, without the fuss of having to do the conversion to a pair of DEs. – J. M.'s missing motivation Mar 29 '17 at 09:21
  • 1
    It might be helpful to attach an Excel sheet as well, so people can compare themselves. (Personally, I have no idea how to solve DEs in Excel.) – Szabolcs Mar 29 '17 at 09:37
  • Beyond changing step sizes, you can customize the method in detail: http://reference.wolfram.com/language/tutorial/NDSolveOverview.html – Szabolcs Mar 29 '17 at 09:38
  • 1
    The only thing I want to say is, NDSolve is very robust in solving initial value problem of ODE(s), it's almost impossible that NDSolve gives a wrong solution in this case. – xzczd Mar 29 '17 at 10:26

0 Answers0