Skip to main content
Mathematics LibreTexts

3.3: The Runge-Kutta Method

  • Page ID
    103485
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\dsum}{\displaystyle\sum\limits} \)

    \( \newcommand{\dint}{\displaystyle\int\limits} \)

    \( \newcommand{\dlim}{\displaystyle\lim\limits} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)

    Each step in Euler’s method requires one evaluation of f and each step in the improved Euler method requires two evaluations of f. We’ll skip methods for which three evaluations of f are used and proceed to the Runge-Kutta method, the most widely used method, for which four evaluations of f are used to solve the initial value problem

    \[\label{eq:3.3.1} y'=f(x,y),\quad y(x_0)=y_0.\]

    The Runge-Kutta method computes approximate values \(y_1\), \(y_2\), …, \(y_n\) of the solution of Equation \ref{eq:3.3.1} at \(x_0\), \(x_0+h\), …, \(x_0+nh\) as follows: Given \(y_i\), compute

    \[\begin{align*} k_{1i}&=f(x_i,y_i),\\ k_{2i}&=f \left(x_i+{h\over2},y_i+{h\over2}k_{1i}\right),\\ k_{3i}&=f\left(x_i+{h\over2},y_i+{h\over2}k_{2i}\right),\\ k_{4i}&=f(x_i+h,y_i+hk_{3i}),\end{align*}\]

    and

    \[y_{i+1}=y_i+{h\over6}(k_{1i}+2k_{2i}+2k_{3i}+k_{4i}).\nonumber \]

    Example 3.3.1 illustrates the computational procedure indicated in the Runge-Kutta method.

    Example 3.3.1

    Use the Runge-Kutta method with \(h=0.1\) to find approximate values for the solution of the initial value problem

    \[\label{eq:3.3.2} y'+2y=x^3e^{-2x},\quad y(0)=1,\]

    at \(x=0.1,0.2\).

    Solution

    Again we rewrite Equation \ref{eq:3.3.2} as

    \[y'=-2y+x^3e^{-2x},\quad y(0)=1, \nonumber\]

    which is of the form Equation \ref{eq:3.3.1}, with

    \[f(x,y)=-2y+x^3e^{-2x},\ x_0=0,\mbox{ and}\ y_0=1. \nonumber\]

    The Runge-Kutta method yields

    \[\begin{aligned} k_{10} & = f(x_0,y_0) = f(0,1)=-2,\\ k_{20} & = f(x_0+h/2,y_0+hk_{10}/2)=f(.05,1+(.05)(-2))\\ &= f(.05,.9)=-2(.9)+(.05)^3e^{-.1}=-1.799886895,\\ k_{30} & = f(x_0+h/2,y_0+hk_{20}/2)=f(.05,1+(.05)(-1.799886895))\\ &= f(.05,.910005655)=-2(.910005655)+(.05)^3e^{-.1}=-1.819898206,\\ k_{40} & = f(x_0+h,y_0+hk_{30})=f(.1,1+(.1)(-1.819898206))\\ &=f(.1,.818010179)=-2(.818010179)+(.1)^3e^{-.2}=-1.635201628,\\ y_1&=y_0+{h\over6}(k_{10}+2k_{20}+2k_{30}+k_{40}),\\ &=1+{.1\over6}(-2+2(-1.799886895)+2(-1.819898206) -1.635201628)=.818753803,\\[4pt] k_{11} & = f(x_1,y_1) = f(.1,.818753803)=-2(.818753803))+(.1)^3e^{-.2}=-1.636688875,\\ k_{21} & = f(x_1+h/2,y_1+hk_{11}/2)=f(.15,.818753803+(.05)(-1.636688875))\\ &= f(.15,.736919359)=-2(.736919359)+(.15)^3e^{-.3}=-1.471338457,\\ k_{31} & = f(x_1+h/2,y_1+hk_{21}/2)=f(.15,.818753803+(.05)(-1.471338457))\\ &= f(.15,.745186880)=-2(.745186880)+(.15)^3e^{-.3}=-1.487873498,\\ k_{41} & = f(x_1+h,y_1+hk_{31})=f(.2,.818753803+(.1)(-1.487873498))\\ &=f(.2,.669966453)=-2(.669966453)+(.2)^3e^{-.4}=-1.334570346,\\ y_2&=y_1+{h\over6}(k_{11}+2k_{21}+2k_{31}+k_{41}),\\ &=.818753803+{.1\over6}(-1.636688875+2(-1.471338457)+2(-1.487873498)-1.334570346) \\&=.670592417.\end{aligned}\]

    The Runge-Kutta method is sufficiently accurate for most applications.

    Examples Illustrating The Error in the Runge-Kutta Method

    Example 3.3.2

    Table 3.3.1 shows results of using the Runge-Kutta method with step sizes \(h=0.1\) and \(h=0.05\) to find approximate values of the solution of the initial value problem

    \[y'+2y=x^3e^{-2x},\quad y(0)=1 \nonumber\]

    at \(x=0\), \(0.1\), \(0.2\), \(0.3\), …, \(1.0\). For comparison, it also shows the corresponding approximate values obtained with the improved Euler method in Example 3.2.2, and the values of the exact solution

    \[y={e^{-2x}\over4}(x^4+4).\nonumber \]

    The results obtained by the Runge-Kutta method are clearly better than those obtained by the improved Euler method in fact; the results obtained by the Runge-Kutta method with \(h=0.1\) are better than those obtained by the improved Euler method with \(h=0.05\).

      Improved Euler Runge-Kutta  
    x h=0.1 h=0.05 h=0.1 h-0.05 Exact
    0.0 1.000000000 1.000000000 1.000000000 1.000000000 1.000000000
    0.1 0.820040937 0.819050572 0.818753803 0.818751370 0.818751221
    0.2 0.672734445 0.671086455 0.670592417 0.670588418 0.670588174
    0.3 0.552597643 0.550543878 0.549928221 0.549923281 0.549922980
    0.4 0.455160637 0.452890616 0.452210430 0.452205001 0.452204669
    0.5 0.376681251 0.374335747 0.373633492 0.373627899 0.373627557
    0.6 0.313970920 0.311652239 0.310958768 0.310953242 0.310952904
    0.7 0.264287611 0.262067624 0.261404568 0.261399270 0.261398947
    0.8 0.225267702 0.223194281 0.222575989 0.222571024 0.222570721
    0.9 0.194879501 0.192981757 0.192416882 0.192412317 0.192412038
    1.0 0.171388070 0.169680673 0.169173489 0.169169356 0.169169104
    Table 3.3.1 : Numerical solution of \(y'+2y=x^3e^{-2x},\ y(0)=1\), by the Runge-Kuttta method and the improved Euler method.
    Example 3.3.3

    Table 3.3.2 shows analogous results for the nonlinear initial value problem

    \[y'=-2y^2+xy+x^2,\ y(0)=1. \nonumber\]

    We applied the improved Euler method to this problem in Example 3.2.3.

      Improved Euler Runge-Kutta  
    x h=0.1 h=0.05 h=0.1 h-0.05 "exact"
    0.0 1.000000000 1.000000000 1.000000000 1.000000000 1.000000000
    0.1 0.840500000 0.838288371 0.837587192 0.837584759 0.837584494
    0.2 0.733430846 0.730556677 0.729644487 0.729642155 0.729641890
    0.3 0.661600806 0.658552190 0.657582449 0.657580598 0.657580377
    0.4 0.615961841 0.612884493 0.611903380 0.611901969 0.611901791
    0.5 0.591634742 0.588558952 0.587576716 0.587575635 0.587575491
    0.6 0.586006935 0.582927224 0.581943210 0.581942342 0.581942225
    0.7 0.597712120 0.594618012 0.593630403 0.593629627 0.593629526
    0.8 0.626008824 0.622898279 0.621908378 0.621907553 0.621907458
    0.9 0.670351225 0.667237617 0.666251988 0.666250942 0.666250842
    1.0 0.730069610 0.726985837 0.726017378 0.726015908 0.726015790
    Table 3.3.2 : Numerical solution of \(y'=-2y^2+xy+x^2,\ y(0)=1\), by the Runge-Kuttta method and the improved Euler method.

    This page titled 3.3: The Runge-Kutta Method is shared under a CC BY-NC-SA 3.0 license and was authored, remixed, and/or curated by William F. Trench via source content that was edited to the style and standards of the LibreTexts platform.