Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2014

[Date Index] [Thread Index] [Author Index]

Search the Archive

Runge-Kutta 2

  • To: mathgroup at smc.vnet.net
  • Subject: [mg132547] Runge-Kutta 2
  • From: amzoti <amzoti at gmail.com>
  • Date: Thu, 10 Apr 2014 03:09:17 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net

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?



  • Prev by Date: Re: How to extract the numerical value of a dynamical variable?
  • Next by Date: Re: Bug with ProbabilityDistribution
  • Previous by thread: Re: Help!
  • Next by thread: Controlling breaking of lines in output of Write