Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

After spending some time using the Mathematica documentation and this Mathematica.SE answer, I implemented the Runge-Kutta-2 routines.

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]

Lastly, 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 Wolfram's Reference page.

Note: I am embarrassed to say that I did not totally understand ClassicalRungeKuttaCoefficients (other than the coefficients).

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.