Categories:
Mathematics,
Numerical methods.
Runge-Kutta method
A Runge-Kutta method (RKM) is a popular approach
to numerically solving systems of ordinary differential equations.
Let x(t) be the vector we want to find,
governed by f(t,x):
x′(t)=f(t,x(t))
Like in all numerical methods, the t-axis is split into discrete steps.
If a step has size h, then as long as h is small enough,
we can make the following approximation:
x′(t)+ahx′′(t)≈x′(t+ah)≈f(t+ah,x(t+ah))≈f(t+ah,x(t)+ahx′(t))
For sufficiently small h,
higher-order derivates can also be included,
albeit still at t+ah:
x′(t)+ahx′′(t)+bh2x′′′(t)≈f(t+ah,x(t)+ahx′(t)+bh2x′′(t))
Although these approximations might seem innocent,
they actually make it quite complicated to determine the error order of a given RKM.
Now, consider a Taylor expansion around the current t,
truncated at a chosen order n:
x(t+h)=x(t)+hx′(t)+2h2x′′(t)+6h3x′′′(t)+...+n!hnx(n)(t)=x(t)+h[x′(t)+2hx′′(t)+6h2x′′′(t)+...+n!hn−1x(n)(t)]
We are free to split the terms as follows,
choosing real factors ωmj subject to ∑jωmj=1:
x(t+h)=x+h[j=1∑N1ω1jx′+2hj=1∑N2ω2jx′′+...+n!hn−1j=1∑Nnωnjx(n)]
Where the integers N1,...,Nn are also free to choose,
but for reasons that will become clear later,
the most general choice for an RKM is N1=n, Nn=1, and:
Nn−1=Nn+2,⋯,Nn−m=Nn−m+1+m+1,⋯,N2=N3+n−1
In other words, Nn−m is the mth triangular number.
This is not so important,
since this is not a practical way to describe RKMs,
but it is helpful to understand how they work.
Example derivation
For example, let us truncate at n=3,
such that N1=3, N2=3 and N3=1.
The following derivation is very general,
except it requires all αj=0.
Renaming ωmj, we start from:
x(t+h)=x+h[(α1+α2+α3)x′+2h(β2+β31+β32)x′′+6h2γ3x′′′]=x+h[α1x′+(α2x′+2hβ2x′′)+(α3x′+2h(β31+β32)x′′+6h2γ3x′′′)]
As discussed earlier, the parenthesized expressions
can be approximately rewritten with f:
x(t+h)=x+h=x+h[α1f(t,x)+α2f(t+2α2hβ2,x+2α2hβ2x′)+α3f(t+2α3h(β31+β32),x+2α3hβ31x′+2α3hβ32x′+6α3h2γ3x′′)][α1k1+α2f(t+2α2hβ2,x+2α2hβ2k1)+α3f(t+2α3h(β31+β32),x+2α3hβ31k1+2α3hβ32f(t+3β32hγ3,x+3β32hγ3k1))]
Here, we can see an opportunity to save some computational time
by reusing an evaluation of f.
Technically, this is optional, but it would be madness not to,
so we choose:
2α2β2=3β32γ3
Such that the next step of x’s numerical solution is as follows,
recalling that ∑jαj=1:
x(t+h)=x(t)+h(α1k1+α2k2+α3k3)
Where k1, k2 and k3 are different estimates
of the average slope x′ between t and t+h,
whose weighted average is used to make the t-step.
They are given by:
k1k2k3≡f(t,x)≡f(t+2α2hβ2,x+2α2hβ2k1)≡f(t+2α3h(β31+β32),x+2α3hβ31k1+2α3hβ32k2)
Despite the contraints on αj and βj,
there is an enormous freedom of choice here,
all leading to valid RKMs, although not necessarily good ones.
A more practical description goes as follows:
in an s-stage RKM, a weighted average is taken
of up to s slope estimates kj with weights bj.
Let ∑jbj=1, then:
x(t+h)=x(t)+hj=1∑sbjkj
Where the estimates k1,...,ks
depend on each other, and are calculated one by one as:
km=f(t+hcm,x+hj=1∑m−1amjkj)
With c1=1 and ∑j=1amj=cm.
Writing this out for the first few m, the pattern is clear:
k1k2k3k4=f(t,x)=f(t+hc2,x+ha21k1)=f(t+hc3,x+h(a31k1+a32k2))=...
The coefficients of a given RKM are usually
compactly represented in a Butcher tableau:
0c2c3⋮csa21a31⋮as1b1a32⋮as2b2⋱⋯⋯as,s−1bs−1bs
Each RKM has an order p,
such that the global truncation error is O(hp),
i.e. the accumulated difference between the numerical
and the exact solutions is proportional to hp.
The surprise is that p need not be equal to the Taylor expansion order n,
nor the stage count s.
Typically, s=n for computational efficiency, but s≥n is possible in theory.
The order p of a given RKM is determined by
a complicated set of equations on the coefficients,
and the lowest possible s for a desired p
is in fact only partially known.
For p≤4 the bound is s≥p,
whereas for p≥5 the only proven bound is s≥p+1,
but for p≥7 no such efficient methods have been found so far.
If you need an RKM with a certain order, look it up.
There exist many efficient methods for p≤4 where s=p,
and although less popular, higher p are also available.
References
- J.C. Butcher,
Numerical methods for ordinary differential equations, 3rd edition,
Wiley.