Professional Documents
Culture Documents
Lecture 11
Lecture 11
Runge-Kutta
Dan Sloughter
Furman University
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 1 / 11
Order of approximations
I One may show that the error in Eulers method is bounded by the
step-size h times a constant. We call Eulers method a first-order
method.
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 2 / 11
Order of approximations
I One may show that the error in Eulers method is bounded by the
step-size h times a constant. We call Eulers method a first-order
method.
I The modified Euler method is a second-order method: the error is
bounded by a constant times h2 .
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 2 / 11
Runge-Kutta method
I Consider the initial-value problem
du
= f (t, u), u(t0 ) = u0 .
dt
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 3 / 11
Runge-Kutta method
I Consider the initial-value problem
du
= f (t, u), u(t0 ) = u0 .
dt
T
I Divide [t0 , t0 + T ] into N equal intervals of length h = N.
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 3 / 11
Runge-Kutta method
I Consider the initial-value problem
du
= f (t, u), u(t0 ) = u0 .
dt
T
I Divide [t0 , t0 + T ] into N equal intervals of length h = N.
I Let ti = t0 + ih, i = 0, 1, 2, . . . , N.
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 3 / 11
Runge-Kutta method
I Consider the initial-value problem
du
= f (t, u), u(t0 ) = u0 .
dt
T
I Divide [t0 , t0 + T ] into N equal intervals of length h = N.
I Let ti = t0 + ih, i = 0, 1, 2, . . . , N.
I Having computed u0 , u1 , . . . , ui , let
k1 = f (ti , ui )
h h
k2 = f ti + , ui + k1
2 2
h h
k3 = f ti + , ui + k2
2 2
k4 = f (ti + h, ui + hk3 ).
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 3 / 11
Runge-Kutta (contd)
I Let
h
ui+1 = ui + (k1 + 2k2 + 2k3 + k4 ) .
6
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 4 / 11
Runge-Kutta (contd)
I Let
h
ui+1 = ui + (k1 + 2k2 + 2k3 + k4 ) .
6
I Runge-Kutta is a fourth-order method.
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 4 / 11
Example
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 5 / 11
Example
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 5 / 11
Example
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 5 / 11
Example (contd)
I And so
0.1
u1 = 1.0 + (1.0 + (2)(1.0486878) + (2)(1.0511191) + 1.0995910)
6
= 1.1049867.
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 6 / 11
Example (contd)
I And so
0.1
u1 = 1.0 + (1.0 + (2)(1.0486878) + (2)(1.0511191) + 1.0995910)
6
= 1.1049867.
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 6 / 11
Example (contd)
I And so
0.1
u1 = 1.0 + (1.0 + (2)(1.0486878) + (2)(1.0511191) + 1.0995910)
6
= 1.1049867.
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 6 / 11
Using Octave
I Runge-Kutta in Octave:
octave:1> function w = f(t,u)
> w = u*cos(t);
> endfunction
octave:2> t = [0:0.1:6];
octave:3> u(1) = 1.0;
octave:4> for i = 1:60
> k1 = f(t(i),u(i));
> k2 = f(t(i)+0.05,u(i)+0.05*k1);
> k3 = f(t(i)+0.05,u(i)+0.05*k2);
> k4 = f(t(i)+0.1,u(i)+0.1*k3);
> u(i+1) = u(i) + (0.1/6)*(k1 + 2*k2 + 2*k3 + k4);
> endfor
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 7 / 11
Using Octave
I Runge-Kutta in Octave:
octave:1> function w = f(t,u)
> w = u*cos(t);
> endfunction
octave:2> t = [0:0.1:6];
octave:3> u(1) = 1.0;
octave:4> for i = 1:60
> k1 = f(t(i),u(i));
> k2 = f(t(i)+0.05,u(i)+0.05*k1);
> k3 = f(t(i)+0.05,u(i)+0.05*k2);
> k4 = f(t(i)+0.1,u(i)+0.1*k3);
> u(i+1) = u(i) + (0.1/6)*(k1 + 2*k2 + 2*k3 + k4);
> endfor
I Note: u(6) u60 = 0.75623, which is exact to 5 decimal places.
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 7 / 11
Using Octave (contd)
I Comparison of exact (green) and approximate (red) solutions:
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 8 / 11
Octave: lsode
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 9 / 11
Octave: lsode
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 9 / 11
lsode (contd)
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 10 / 11
lsode (contd)
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 10 / 11
lsode (contd)
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 10 / 11
lsode (contd)
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 10 / 11
lsode (contd)
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 10 / 11
Runge-Kutta in Maxima
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 11 / 11
Runge-Kutta in Maxima
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 11 / 11
Runge-Kutta in Maxima
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 11 / 11
Runge-Kutta in Maxima
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 11 / 11
Runge-Kutta in Maxima
Dan Sloughter (Furman University) Mathematics 22: Lecture 11 January 25, 2008 11 / 11