Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #16764

Runge-Kutta 2

From amzoti <amzoti@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Runge-Kutta 2
Date 2014-04-10 07:09 +0000
Message-ID <li5g3d$3lc$1@smc.vnet.net> (permalink)
Organization Time-Warner Telecom

Show all headers | View raw


After spending some time using the Mathematica documentation I implemented the Runge-Kutta-2 routines below.

I am hoping someone can validate what I did and tell me that it is correct (especially the Butcher Tableau I used) and the step size h=0.1.

  ClassicalRungeKuttaCoefficients[4, prec_] :=
   With[{amat = {{1/2}}, bvec = {0, 1}, cvec = {1/2}},
    N[{amat, bvec, cvec}, prec]]

  {xf, yf} = {x, y} /.
    First@NDSolve[{x'[t] == -y[t], y'[t] == x[t], x[0] == 1,
     y[0] == 0}, {x, y}, {t, 0, 6},
     Method -> {"ExplicitRungeKutta", "DifferenceOrder" -> 4,
    "Coefficients" -> ClassicalRungeKuttaCoefficients},
     StartingStepSize -> 1/10];

  xl = MapThread[Append, {xf["Grid"], xf["ValuesOnGrid"]}]

  yl = MapThread[Append, {yf["Grid"], yf["ValuesOnGrid"]}]

We can find a closed form solution to this problem as:

  s = DSolve[{x'[t] == -y[t], y'[t] == x[t], x[0] == 1, y[0] == 0}, {x, y}, t]

Is there an automated way to update and step through each variant of RK-2, RK-3, RK-4, ... without having to manually enter the Butcher values (in other words, I want to step through each variant of RK-n and compare the errors (a table of that would be great))? There is a hint of this at: http://reference.wolfram.com/mathematica/tutorial/NDSolveExplicitRungeKutta.html

Lastly, is there a better approach?

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar


Thread

Runge-Kutta 2 amzoti <amzoti@gmail.com> - 2014-04-10 07:09 +0000

csiph-web