Upload
phungthien
View
232
Download
2
Embed Size (px)
Citation preview
Section 7.4 Runge-Kutta Methods
Key terms:
• Taylor methods
• Taylor series
• Runge-Kutta; methods linear combinations of function values at
intermediate points
• Alternatives to second order Taylor methods
• Fourth order Runge-Kutta methods; very popular
Taylor methods require derivatives of f(t, y), which makes them difficult to use
effectively. This drawback is so severe that they are seldom used in practice.
However, there is another approach that is very effective.
Runge-Kutta methods are related to Taylor methods in the following way. Instead of
using derivatives of f(t, y), Runge-Kutta methods use evaluations of the f(t, y) at
“alternative pairs” of points (t, y) that are not restricted to discrete points
with t = t0, t1 = t0+h, t2 = t0 + 2h, … etc.
These techniques were developed around 1900 by the German mathematicians
C. Runge and M.W. Kutta.
The determination of these “alternative pairs” requires certain parameters to be
selected so that we match the Taylor expressions and maintain the same power
of stepsize h in the error expression.
The advantage of this approach is that we use only evaluations of f not its
derivatives. Thus the cost of using Runge-Kutta methods is FUNCTION
EVALUATIONS instead of DERIVATIVE EVALUATIONS. Hence the Runge-Kutta
methods are simple to use and have error properties corresponding to the
Taylor methods upon which they are based.
The development of R-K methods expresses the difference between y(tn+1) and
y(tn) as a linear combination of function evaluations of f(t, y(t)). Then
coefficients in such linear combinations are determined so that terms of Taylor
expansions are matched.
The general approach is to construct a
difference equation of the form
where the coefficients aj are
constants and the kj are expressions
involving stepsize h times evaluations
of function f. That is,
where the coefficients aj, αj, and βjs are chosen to match terms of the
Taylor expansion of y(t). (Note that kj can depend on values of previous
k’s and the value tn + αjh ≤ tn+1.)
Example:
Construct a R-K method of the form
We use Taylor expansions for the corresponding expression involving the exact
solution y(t), which looks like then following. (We replace w’s with y(t).)
We choose parameters a1, a2, α, and β to match terms of the expansion
When we do this (via ugly algebra & calculus) we get THREE EQUATIONS
in FOUR UNKNOWNS (nonlinear system).
Recall that
When these equations are satisfied then the R-K method
has local truncation error O(h2). That is, it will in effect act
like a second order Taylor method, but with a (somewhat)
different error expression.
Since we have a nonlinear system of 3 equations in 4 unknowns we
expect many solutions.
Some particular choices for the parameters a1, a2, α, and β:
(Warning: the names vary from book to book. The names used here
correspond to those used in MATLAB software and are not the same as
those used in the text by Bradie.)
Midpoint Method
Modified Euler Method
Heun’s Method
Bradie name,Modified
Euler method
Bradie name,Heun
method
Bradie name,
Optimal RK2 method
Higher order R-K methods are
constructed in a similar way just using
more terms of the difference equation
with
and of course matching more terms of the Taylor expansion of y(t+h). The algebra
& calculus becomes very tedious. One of the most popular R-K methods is a 4th
order method given by the following:
Note that the
k-values must
be computed
in order.
The main computational effort in RK-methods is evaluating f.
There should be some payoff to using
a method like RK4. We hope that such
higher order methods will let us use
larger step sizes h and maintain the
same accuracy as lower order methods
with smaller step sizes.
Exact
solution
(-t)
1y(t) =
e2
In a graph
the sets of
data look
coincident.
RK4 should give more accurate answers than
Euler’s method with about a stepsize about 4
times larger.
RK4 should give more accurate answers
than RK2 with about a stepsize about 2
times larger.
To get methods which are as accurate as RK-methods, but with fewer
evaluations of f, we need to use multistep methods. (Discussed in the
next section.)
The RK2 Midpoint Method is given by
Example:
is evaluated where t is
and y is
This is what you
substitute for t.
This is what you
substitute for y.
If you had to use one of the Runge-Kutta methods by hand (calculator) care
must be used to get the substitutions correct. We illustrate this below.
A comparison of behaviors:
MATLAB command names:
eulersys
rkmidpt
rkmodeuler
rkheun
rk4th
All of these routines are designed to handles systems of ODEs:
The system has the form
X' = F(t,X)
X(t0) = X0 <-- initial condition
where X is column vector and F is a vector function.
The independent variable is t and the components of F(X)
are functions of the variables
t and x(1), x(2), ..., x(k), for k<=9.
Before using any of these read the help files carefully.
The names used by the m-files are different than names appearing in the
text.
Example: Use rk4th on IVP y’ = y – t2 + 1, 0 ≤ t ≤ 2, y(0) = 0.5 with stepsize h = 0.1 .
Use command >>rk4th
What you see on the MATLAB screen that requests input:
Enter size (<= 9) of the system: k = 1
Enter f1 = x(1)-t^2+1
Your system is X' =
x(1)-t^2+1
1 Accept current functions in f.
2 Re-enter functions.
0 Quit!
Enter your choice ---> 1
Enter the initial condition X(t0) = [x1 x2 ...xk]
Enter value of t0: t0 = 0
Enter 1 initial values in the form [a b .. etc]: X(t0) = 0.5
Enter right end of solution interval: b = 2
Enter the stepsize: h = 0.1
The solution at t = b is
W =
5.3055e+00
You can see a table of output by
performing several more steps:
t w
0 0.5000
0.1000 0.6574
0.2000 0.8293
0.3000 1.0151
0.4000 1.2141
0.5000 1.4256
0.6000 1.6489
0.7000 1.8831
0.8000 2.1272
0.9000 2.3802
1.0000 2.6409
1.1000 2.9079
1.2000 3.1799
1.3000 3.4553
1.4000 3.7324
1.5000 4.0092
1.6000 4.2835
1.7000 4.5530
1.8000 4.8152
1.9000 5.0670
2.0000 5.3055
The true solution is,
y = 2t -0.5et + t2 + 1
so you could
consturct the error at
each t value and
graph the error.
Input in red output in blue. B&F 5.4
Examp 4
How do you approximate the solution of an IVP whose DE is more than first
order?
Answer: Convert the higher order DE to a system of first order DEs.
Example: Use rk4th to approximate the solution of the IVP
2 32 2 1 2 1 1 1 0 with 0 1t y'' ty' y t ln(t), t , y( ) , y'( ) , h .
The true solution is . 3 37 1 3
4 2 4y(t) t t ln(t) t
Let . 1
2
u (t) y(t)
u (t) y'(t)
Now differentiate to get .
1 2
2 2 12
2 2
u ' y' u
u ' y'' u u t ln(t)t t
Enter size (<= 9) of the system: k = 2
Enter f1 = x(2)
Enter f2 = (2/t)*x(2)-(2/t^2)*x(1)+t*log(t)
Enter the initial condition X(t0) = [x1 x2 ...xk]
Enter value of t0: t0 = 1
Enter 2 initial values in the form [a b .. etc]: X(t0) = [1 0]
Enter right end of solution interval: b = 2
Enter the stepsize: h = 0.1
The solution at t = b is
W =
2.7258e-01
-1.0911e+00
Linear second order
nonhomogenous DE
rk4th
INPUT
B&F 5.9
#3b
u1 x(1); u2 x(2) in rk4th
f1 f2
t u1(t) u2(t)
1.0000 1.0000 0
1.1000 0.9902 -0.1945
1.2000 0.9615 -0.3762
1.3000 0.9155 -0.5424
1.4000 0.8536 -0.6908
1.5000 0.7780 -0.8191
1.6000 0.6906 -0.9252
1.7000 0.5937 -1.0072
1.8000 0.4900 -1.0634
1.9000 0.3820 -1.0919
2.0000 0.2726 -1.0911
t y(t)
1.0000 1.0000
1.1000 0.9902
1.2000 0.9615
1.3000 0.9155
1.4000 0.8536
1.5000 0.7780
1.6000 0.6906
1.7000 0.5937
1.8000 0.4900
1.9000 0.3820
2.0000 0.2726
From rk4th From true soln
t absolute error
1.0000e+00 0
1.1000e+00 7.4726e-07
1.2000e+00 1.4532e-06
1.3000e+00 2.1266e-06
1.4000e+00 2.7742e-06
1.5000e+00 3.4014e-06
1.6000e+00 4.0122e-06
1.7000e+00 4.6099e-06
1.8000e+00 5.1973e-06
1.9000e+00 5.7764e-06
2.0000e+00 6.3491e-06
Absolute
error True
soln.