Differential EquationsApplications of Systems3 of 3
Applications of Systems · 3

Numerical Methods for Systems

Most systems of differential equations cannot be solved with algebra and calculus, so we need a way to trace out where x(t)\xvar{x(t)} and y(t)\yvar{y(t)} go over time step by step.

1

Following Arrows in the Phase Plane

Given the system

x′\displaystyle \xvar{x'} =y,y′\displaystyle = \yvar{y}, \qquad \yvar{y'} =−x\displaystyle = -\xvar{x}

and a starting point (1,0)(1, 0), we want to track the path of the point (x,y)(\xvar{x}, \yvar{y}) in the x\xvar{x}-y\yvar{y} phase plane.

For a single differential equation, Euler's method steps forward along the current rate of change for a small time step:

New Value\displaystyle \text{New Value} =Old Value+(Rate of Change)×(Time Step)\displaystyle = \text{Old Value} + (\rate{\text{Rate of Change}}) \times (\text{Time Step})

When two variables change together, the system tells us both components of our velocity arrow at the current point.

x\htmlClass{lc-blue}{x}
y\htmlClass{lc-orange}{y}
(x, y)(\htmlClass{lc-blue}{x},\ \htmlClass{lc-orange}{y})
x′\htmlClass{lc-blue}{x'}
y′\htmlClass{lc-orange}{y'}
Following Arrows in the Phase Plane
x\htmlClass{lc-blue}{x}
y\htmlClass{lc-orange}{y}
x(t)=?\htmlClass{lc-blue}{x(t)} = {?}
y(t)=?\htmlClass{lc-orange}{y(t)} = {?}

Because x′\xvar{x'} is the horizontal speed and y′\yvar{y'} is the vertical speed at your current point, stepping along the arrow means applying the Euler stepping rule to both coordinates at the same time:

New x=Old x+(x’s rate)×(step)New y=Old y+(y’s rate)×(step)\displaystyle \begin{aligned} \text{New } \xvar{x} &= \text{Old } \xvar{x} + (\xvar{x\text{'s rate}}) \times (\text{step}) \\ \text{New } \yvar{y} &= \text{Old } \yvar{y} + (\yvar{y\text{'s rate}}) \times (\text{step}) \end{aligned}

Taking straight Euler steps from one velocity arrow to the next traces out an approximate path, though on curves those straight steps drift slightly outward.

Every point sets your horizontal and vertical speed at the same time, and stepping straight from arrow to arrow makes you drift outward off the circle.
2

Euler's Method on a System

Now let's use this stepping rule on a system where the rates of change also depend on time tt. For the system

x′\displaystyle \xvar{x'} =x+y,y′\displaystyle = \xvar{x} + \yvar{y}, \qquad \yvar{y'} =2t−x\displaystyle = 2t - \xvar{x}

starting at t=0, x=1, y=2t = 0, \, \xvar{x} = 1, \, \yvar{y} = 2, we want to estimate x\xvar{x} and y\yvar{y} at t=0.2t = 0.2 using Euler's method with step size h=0.1h = 0.1.

Euler's Method on a System
x\htmlClass{lc-blue}{x}
y\htmlClass{lc-orange}{y}
x′=x+yy′=2t−x\begin{aligned} \htmlClass{lc-blue}{x'} &= \htmlClass{lc-blue}{x} + \htmlClass{lc-orange}{y} \\ \htmlClass{lc-orange}{y'} &= 2t - \htmlClass{lc-blue}{x} \end{aligned}
h=0.1h = 0.1
x(0.2), y(0.2)=?\htmlClass{lc-blue}{x(0.2)},\ \htmlClass{lc-orange}{y(0.2)} = {?}
(1, 2)(1,\ 2)
t=0t = 0
Text solution
Both rates at t=0t = 0Plug the starting values t=0, x=1, y=2t = 0, \, \xvar{x} = 1, \, \yvar{y} = 2 into both equations before moving either variable.
x′=1+2=3y′=2(0)−1=0−1=−1\displaystyle \begin{aligned} \xvar{x'} &= 1 + 2 = \xvar{3} \\ \yvar{y'} &= 2(0) - 1 = 0 - 1 = \yvar{-1} \end{aligned}
First step to t=0.1t = 0.1Step x\xvar{x} and y\yvar{y} forward together by h=0.1h = 0.1 using those starting rates.
New x=1+(3)(0.1)=1+0.3=1.3New y=2+(−1)(0.1)=2−0.1=1.9\displaystyle \begin{aligned} \text{New } \xvar{x} &= 1 + (\xvar{3})(0.1) \\ &= 1 + 0.3 = 1.3 \\ \text{New } \yvar{y} &= 2 + (\yvar{-1})(0.1) \\ &= 2 - 0.1 = 1.9 \end{aligned}
Both rates at t=0.1t = 0.1Plug the new values t=0.1, x=1.3, y=1.9t = 0.1, \, \xvar{x} = 1.3, \, \yvar{y} = 1.9 into both equations to find the next pair of rates.
x′=1.3+1.9=3.2y′=2(0.1)−1.3=0.2−1.3=−1.1\displaystyle \begin{aligned} \xvar{x'} &= 1.3 + 1.9 = \xvar{3.2} \\ \yvar{y'} &= 2(0.1) - 1.3 \\ &= 0.2 - 1.3 = \yvar{-1.1} \end{aligned}
Second step to t=0.2t = 0.2Step both variables forward together by h=0.1h = 0.1 to reach t=0.2t = 0.2.
New x=1.3+(3.2)(0.1)=1.3+0.32=1.62New y=1.9+(−1.1)(0.1)=1.9−0.11=1.79\displaystyle \begin{aligned} \text{New } \xvar{x} &= 1.3 + (\xvar{3.2})(0.1) \\ &= 1.3 + 0.32 = 1.62 \\ \text{New } \yvar{y} &= 1.9 + (\yvar{-1.1})(0.1) \\ &= 1.9 - 0.11 = 1.79 \end{aligned}

So after two steps, at t=0.2t = 0.2, Euler's method estimates x=1.62\xvar{x} = 1.62 and y=1.79\yvar{y} = 1.79.

You might also see this rule written with subscripts, where nn marks the values at the start of the step:

xn+1=xn+h⋅f(tn,xn,yn)⏟old x’s rateyn+1=yn+h⋅g(tn,xn,yn)⏟old y’s rate\displaystyle \begin{aligned} \xvar{x_{n+1}} &= \xvar{x_n} + h \cdot \underbrace{\xvar{f}(t_n, \xvar{x_n}, \yvar{y_n})}_{\text{old } \xvar{x\text{'s rate}}} \\ \yvar{y_{n+1}} &= \yvar{y_n} + h \cdot \underbrace{\yvar{g}(t_n, \xvar{x_n}, \yvar{y_n})}_{\text{old } \yvar{y\text{'s rate}}} \end{aligned}
3

Turning a Second-Order Equation into a System

Euler's method needs first-order rates of change, so what do we do when a physics problem gives us acceleration y′′\acc{y''} instead? For the damped spring equation

y′′\displaystyle \acc{y''} =−2y−3y′\displaystyle = -2\pos{y} - 3\vel{y'}

starting at t=0t = 0 with position y=1\pos{y} = 1 and velocity y′=0\vel{y'} = 0, we want to estimate the position and velocity at t=0.2t = 0.2 using step size h=0.1h = 0.1.

Turning a Second-Order Equation into a System
y′′=−2y−3y′\htmlClass{lc-orange}{y''} = -2\htmlClass{lc-blue}{y} - 3\htmlClass{lc-pink}{y'}
y=1\htmlClass{lc-blue}{y} = 1
y′=0\htmlClass{lc-pink}{y'} = 0
h=0.1h = 0.1
y(0.2), y′(0.2)=?\htmlClass{lc-blue}{y(0.2)},\ \htmlClass{lc-pink}{y'(0.2)} = {?}
y\htmlClass{lc-blue}{y}
00
11
Text solution
Rewrite as a first-order systemName velocity v=y′\vel{v} = \vel{y'} so that position's rate of change is v\vel{v} and velocity's rate of change is the acceleration y′′\acc{y''}.
y′=vv′=−2y−3v\displaystyle \begin{aligned} \vel{y'} &= \vel{v} \\ \acc{v'} &= -2\pos{y} - 3\vel{v} \end{aligned}
Both rates at t=0t = 0Plug the starting position y=1\pos{y} = 1 and starting velocity v=0\vel{v} = 0 into both equations.
y′=0v′=−2(1)−3(0)=−2−0=−2\displaystyle \begin{aligned} \vel{y'} &= \vel{0} \\ \acc{v'} &= -2(1) - 3(0) = -2 - 0 = \acc{-2} \end{aligned}
First step to t=0.1t = 0.1Step position y\pos{y} and velocity v\vel{v} forward together by h=0.1h = 0.1.
New y=1+(0)(0.1)=1+0=1New v=0+(−2)(0.1)=0−0.2=−0.2\displaystyle \begin{aligned} \text{New } \pos{y} &= 1 + (\vel{0})(0.1) \\ &= 1 + 0 = 1 \\ \text{New } \vel{v} &= 0 + (\acc{-2})(0.1) \\ &= 0 - 0.2 = -0.2 \end{aligned}
Both rates at t=0.1t = 0.1Plug the new position y=1\pos{y} = 1 and velocity v=−0.2\vel{v} = -0.2 into both equations.
y′=−0.2v′=−2(1)−3(−0.2)=−2+0.6=−1.4\displaystyle \begin{aligned} \vel{y'} &= \vel{-0.2} \\ \acc{v'} &= -2(1) - 3(-0.2) \\ &= -2 + 0.6 = \acc{-1.4} \end{aligned}
Second step to t=0.2t = 0.2Step both position and velocity forward by h=0.1h = 0.1 to reach t=0.2t = 0.2.
New y=1+(−0.2)(0.1)=1−0.02=0.98New v=−0.2+(−1.4)(0.1)=−0.2−0.14=−0.34\displaystyle \begin{aligned} \text{New } \pos{y} &= 1 + (\vel{-0.2})(0.1) \\ &= 1 - 0.02 = 0.98 \\ \text{New } \vel{v} &= -0.2 + (\acc{-1.4})(0.1) \\ &= -0.2 - 0.14 = -0.34 \end{aligned}

So at t=0.2t = 0.2, Euler's method estimates position y=0.98\pos{y} = 0.98 and velocity v=−0.34\vel{v} = -0.34. Notice that the estimated position stayed at 11 during the first step because that step uses the starting velocity, 00, and only started moving downward on the second step once the velocity was no longer 00.

4

Why Euler Spirals and Improved Euler Fixes It

Stepping straight along the starting arrow works over tiny distances, but on a curving path like a circle, walking along the tangent line goes slightly outside the circle on every step. Starting at (1,0)(1, 0) on the circle system

x′\displaystyle \xvar{x'} =y,y′\displaystyle = \yvar{y}, \qquad \yvar{y'} =−x\displaystyle = -\xvar{x}

we want to take a step of size h=0.1h = 0.1 that curves with the circle instead of spiraling outward.

x\htmlClass{lc-blue}{x}
y\htmlClass{lc-orange}{y}
Euler\text{Euler}
(1, 0)(1,\ 0)
x\htmlClass{lc-blue}{x}
y\htmlClass{lc-orange}{y}
Improved Euler\text{Improved Euler}
(1, 0)(1,\ 0)

Remember that for a single equation, Improved Euler fixes this tangent drift by taking a trial step to the end of the interval, checking the new slope there, and averaging the starting slope and trial slope before taking the real step.

Why Euler Spirals and Improved Euler Fixes It
x\htmlClass{lc-blue}{x}
y\htmlClass{lc-orange}{y}
x′=yy′=−x\begin{aligned} \htmlClass{lc-blue}{x'} &= \htmlClass{lc-orange}{y} \\ \htmlClass{lc-orange}{y'} &= -\htmlClass{lc-blue}{x} \end{aligned}
h=0.1h = 0.1
(1, 0)(1,\ 0)
Text solution
Starting slopes at (1,0)(1, 0)Find both velocity components at the starting point (1,0)(1, 0).
x1′=0y1′=−1\displaystyle \begin{aligned} \xvar{x'_1} &= \xvar{0} \\ \yvar{y'_1} &= \yvar{-1} \end{aligned}
Trial step to the end of the intervalStep both x\xvar{x} and y\yvar{y} forward by h=0.1h = 0.1 using the starting slopes to reach the trial point.
Trial x=1+(0)(0.1)=1+0=1Trial y=0+(−1)(0.1)=0−0.1=−0.1\displaystyle \begin{aligned} \text{Trial } \xvar{x} &= 1 + (\xvar{0})(0.1) \\ &= 1 + 0 = 1 \\ \text{Trial } \yvar{y} &= 0 + (\yvar{-1})(0.1) \\ &= 0 - 0.1 = -0.1 \end{aligned}
Trial slopes at (1,−0.1)(1, -0.1)Plug both coordinates of the trial point into the system to find the new arrow at the end of the step.
x2′=−0.1y2′=−1\displaystyle \begin{aligned} \xvar{x'_2} &= \xvar{-0.1} \\ \yvar{y'_2} &= \yvar{-1} \end{aligned}
Average both pairs of slopesAverage the starting rate and trial rate for x\xvar{x}, and do the same for y\yvar{y}.
Average x rate=0+(−0.1)2=−0.05Average y rate=−1+(−1)2=−1\displaystyle \begin{aligned} \text{Average } \xvar{x\text{ rate}} &= \frac{\xvar{0} + (\xvar{-0.1})}{2} \\ &= \xvar{-0.05} \\ \text{Average } \yvar{y\text{ rate}} &= \frac{\yvar{-1} + (\yvar{-1})}{2} \\ &= \yvar{-1} \end{aligned}
Real step from (1,0)(1, 0)Go back to the starting point (1,0)(1, 0) and step forward by h=0.1h = 0.1 using the average rates.
New x=1+(−0.05)(0.1)=1−0.005=0.995New y=0+(−1)(0.1)=0−0.1=−0.1\displaystyle \begin{aligned} \text{New } \xvar{x} &= 1 + (\xvar{-0.05})(0.1) \\ &= 1 - 0.005 = 0.995 \\ \text{New } \yvar{y} &= 0 + (\yvar{-1})(0.1) \\ &= 0 - 0.1 = -0.1 \end{aligned}

Averaging with the inward-tilted arrow at the trial point pulls x\xvar{x} inward from 11 to 0.9950.995. The exact solution is x=cos⁡t\xvar{x} = \cos t, y=−sin⁡t\yvar{y} = -\sin t, so the true value at t=0.1t = 0.1 is x=cos⁡(0.1)≈0.995004\xvar{x} = \cos(0.1) \approx 0.995004, very close to our estimate.

Stepping straight along the starting tangent always lands outside the unit circle, while averaging the starting arrow with the inward-tilted trial arrow pulls the step back almost onto the circle.
5

Stepping a System with Improved Euler

Now let's run one step of Improved Euler when time tt also appears in the system. For our earlier system

x′\displaystyle \xvar{x'} =x+y,y′\displaystyle = \xvar{x} + \yvar{y}, \qquad \yvar{y'} =2t−x\displaystyle = 2t - \xvar{x}

starting at t=0, x=1, y=2t = 0, \, \xvar{x} = 1, \, \yvar{y} = 2, we want to estimate x(0.1)\xvar{x(0.1)} and y(0.1)\yvar{y(0.1)} with step size h=0.1h = 0.1.

Stepping a System with Improved Euler
x′\displaystyle \htmlClass{lc-blue}{x'} =x+y,y′\displaystyle = \htmlClass{lc-blue}{x} + \htmlClass{lc-orange}{y}, \qquad \htmlClass{lc-orange}{y'} =2t−x\displaystyle = 2t - \htmlClass{lc-blue}{x}
Improved Euler,h\displaystyle \text{Improved Euler}, \quad h =0.1\displaystyle = 0.1
txy0120.1??\displaystyle \begin{array}{c|c|c} t & \htmlClass{lc-blue}{x} & \htmlClass{lc-orange}{y} \\ \hline 0 & 1 & 2 \\ 0.1 & ? & ? \end{array}
Text solution
Starting slopes at t=0t = 0Plug t=0, x=1, y=2t = 0, \, \xvar{x} = 1, \, \yvar{y} = 2 into both equations.
x1′=1+2=3y1′=2(0)−1=0−1=−1\displaystyle \begin{aligned} \xvar{x'_1} &= 1 + 2 = \xvar{3} \\ \yvar{y'_1} &= 2(0) - 1 = 0 - 1 = \yvar{-1} \end{aligned}
Trial step to t=0.1t = 0.1Step tt, x\xvar{x}, and y\yvar{y} forward together by h=0.1h = 0.1 using the starting slopes.
Trial t=0+0.1=0.1Trial x=1+(3)(0.1)=1+0.3=1.3Trial y=2+(−1)(0.1)=2−0.1=1.9\displaystyle \begin{aligned} \text{Trial } t &= 0 + 0.1 = 0.1 \\ \text{Trial } \xvar{x} &= 1 + (\xvar{3})(0.1) \\ &= 1 + 0.3 = 1.3 \\ \text{Trial } \yvar{y} &= 2 + (\yvar{-1})(0.1) \\ &= 2 - 0.1 = 1.9 \end{aligned}
Trial slopes at the trial pointPlug Trial t=0.1, Trial x=1.3, Trial y=1.9\text{Trial } t = 0.1, \, \text{Trial } \xvar{x} = 1.3, \, \text{Trial } \yvar{y} = 1.9 into both equations.
x2′=1.3+1.9=3.2y2′=2(0.1)−1.3=0.2−1.3=−1.1\displaystyle \begin{aligned} \xvar{x'_2} &= 1.3 + 1.9 = \xvar{3.2} \\ \yvar{y'_2} &= 2(0.1) - 1.3 \\ &= 0.2 - 1.3 = \yvar{-1.1} \end{aligned}
Average both pairs of slopesAverage the starting slope and trial slope for each variable.
Average x rate=3+3.22=6.22=3.1Average y rate=−1+(−1.1)2=−2.12=−1.05\displaystyle \begin{aligned} \text{Average } \xvar{x\text{ rate}} &= \frac{\xvar{3} + \xvar{3.2}}{2} \\ &= \frac{6.2}{2} = \xvar{3.1} \\ \text{Average } \yvar{y\text{ rate}} &= \frac{\yvar{-1} + (\yvar{-1.1})}{2} \\ &= \frac{-2.1}{2} = \yvar{-1.05} \end{aligned}
Real step from (1,2)(1, 2)Go back to the starting point (1,2)(1, 2) and step forward by h=0.1h = 0.1 using the average rates.
New x=1+(3.1)(0.1)=1+0.31=1.31New y=2+(−1.05)(0.1)=2−0.105=1.895\displaystyle \begin{aligned} \text{New } \xvar{x} &= 1 + (\xvar{3.1})(0.1) \\ &= 1 + 0.31 = 1.31 \\ \text{New } \yvar{y} &= 2 + (\yvar{-1.05})(0.1) \\ &= 2 - 0.105 = 1.895 \end{aligned}

So at t=0.1t = 0.1, Improved Euler estimates x=1.31\xvar{x} = 1.31 and y=1.895\yvar{y} = 1.895, improving on the basic Euler estimate (1.3,1.9)(1.3, 1.9) by accounting for how both slopes change across the step.

6

RK4 on a System

When we need high accuracy over longer steps, the fourth-order Runge-Kutta method (RK4) checks the velocity arrow four times across the step instead of twice. Just as in single-variable RK4, we step from the starting point to two midpoints at h2\tfrac{h}{2} and to the endpoint at hh, then combine the four slopes with weights 1,2,2,11, 2, 2, 1.

RK4 on a System
x\htmlClass{lc-blue}{x}
y\htmlClass{lc-orange}{y}
x′=yy′=−x\begin{aligned} \htmlClass{lc-blue}{x'} &= \htmlClass{lc-orange}{y} \\ \htmlClass{lc-orange}{y'} &= -\htmlClass{lc-blue}{x} \end{aligned}
(k1x, k1y)(\htmlClass{lc-blue}{k_{1x}},\ \htmlClass{lc-orange}{k_{1y}})
tt
t+ht + h
(Old x, Old y)(\text{Old } \htmlClass{lc-blue}{x},\ \text{Old } \htmlClass{lc-orange}{y})
(k1x, k1y)(\htmlClass{lc-blue}{k_{1x}},\ \htmlClass{lc-orange}{k_{1y}})
h2\tfrac{h}{2}
(k2x, k2y)(\htmlClass{lc-blue}{k_{2x}},\ \htmlClass{lc-orange}{k_{2y}})
h2\tfrac{h}{2}
(k3x, k3y)(\htmlClass{lc-blue}{k_{3x}},\ \htmlClass{lc-orange}{k_{3y}})
hh
(k4x, k4y)(\htmlClass{lc-blue}{k_{4x}},\ \htmlClass{lc-orange}{k_{4y}})
(New x, New y)(\text{New } \htmlClass{lc-blue}{x},\ \text{New } \htmlClass{lc-orange}{y})

At every stage of RK4, we step both variables from the original point (Old x,Old y)(\text{Old } \xvar{x}, \text{Old } \yvar{y}) before finding the next slope pair, and tt moves along with them, to Old t+h2\text{Old } t + \tfrac{h}{2} at both midpoints and Old t+h\text{Old } t + h at the endpoint:

Key concepts

Every numerical method on a system follows the same pattern: find both slopes at the current point first, then move all variables together from the start of the step.

When to rewrite first

If the system already gives first derivatives like x′=x+y, y′=2t−x\xvar{x'} = \xvar{x} + \yvar{y}, \, \yvar{y'} = 2t - \xvar{x}, step x\xvar{x} and y\yvar{y} directly without introducing any extra variable. Only when an equation has a second derivative y′′\acc{y''}, such as y′′=−2y−3y′\acc{y''} = -2\pos{y} - 3\vel{y'}, do you introduce velocity v=y′\vel{v} = \vel{y'} to turn it into the first-order system y′=v, v′=−2y−3v\vel{y'} = \vel{v}, \, \acc{v'} = -2\pos{y} - 3\vel{v}.

Euler's method (one slope pair per step)

Find (x′,y′)(\xvar{x'}, \yvar{y'}) at the start of the step and step both variables together:

New x=Old x+(x’s rate)h,New y=Old y+(y’s rate)h\displaystyle \begin{aligned} \text{New } \xvar{x} &= \text{Old } \xvar{x} + (\xvar{x\text{'s rate}})h, \\ \text{New } \yvar{y} &= \text{Old } \yvar{y} + (\yvar{y\text{'s rate}})h \end{aligned}
For x′=x+y, y′=2t−x\xvar{x'} = \xvar{x} + \yvar{y}, \, \yvar{y'} = 2t - \xvar{x} at (0,1,2)(0, 1, 2) with h=0.1h = 0.1, finding x′=3\xvar{x'} = \xvar{3} and y′=−1\yvar{y'} = \yvar{-1} before moving gives x(0.1)=1+3(0.1)=1.3\xvar{x(0.1)} = 1 + \xvar{3}(0.1) = 1.3 and y(0.1)=2+(−1)(0.1)=1.9\yvar{y(0.1)} = 2 + (\yvar{-1})(0.1) = 1.9. Basic Euler is quick for rough steps, but on curved phase-plane paths like x′=y, y′=−x\xvar{x'} = \yvar{y}, \, \yvar{y'} = -\xvar{x} it walks straight along tangents and spirals outward.

Improved Euler (two slope pairs per step)

Use the starting slopes (x1′,y1′)(\xvar{x'_1}, \yvar{y'_1}) to take a trial step of size hh for tt, x\xvar{x}, and y\yvar{y} together, find the trial slopes (x2′,y2′)(\xvar{x'_2}, \yvar{y'_2}) there, and step from the original starting point using the average rates x1′+x2′2\frac{\xvar{x'_1} + \xvar{x'_2}}{2} and y1′+y2′2\frac{\yvar{y'_1} + \yvar{y'_2}}{2}. On x′=y, y′=−x\xvar{x'} = \yvar{y}, \, \yvar{y'} = -\xvar{x} from (1,0)(1, 0), averaging (0,−1)(\xvar{0}, \yvar{-1}) at the start with (−0.1,−1)(\xvar{-0.1}, \yvar{-1}) at the trial point (1,−0.1)(1, -0.1) gives average rates (−0.05,−1)(\xvar{-0.05}, \yvar{-1}) and pulls the step inward to (0.995,−0.1)(0.995, -0.1).

RK4 (four slope pairs per step)

Find (k1x,k1y)(\xvar{k_{1x}}, \yvar{k_{1y}}) at the start, step from the start by h2\tfrac{h}{2} to find (k2x,k2y)(\xvar{k_{2x}}, \yvar{k_{2y}}), step from the start by h2\tfrac{h}{2} again with k2\rate{k_2} to find (k3x,k3y)(\xvar{k_{3x}}, \yvar{k_{3y}}), and step from the start by hh with k3\rate{k_3} to find (k4x,k4y)(\xvar{k_{4x}}, \yvar{k_{4y}}). Then step from the original starting point using the 1,2,2,11, 2, 2, 1 weighted averages:

New x=Old x+hk1x+2k2x+2k3x+k4x6,New y=Old y+hk1y+2k2y+2k3y+k4y6\displaystyle \begin{aligned} &\text{New } \xvar{x} = \text{Old } \xvar{x} \\ &\quad + h\frac{\xvar{k_{1x}} + 2\xvar{k_{2x}} + 2\xvar{k_{3x}} + \xvar{k_{4x}}}{6}, \\ &\text{New } \yvar{y} = \text{Old } \yvar{y} \\ &\quad + h\frac{\yvar{k_{1y}} + 2\yvar{k_{2y}} + 2\yvar{k_{3y}} + \yvar{k_{4y}}}{6} \end{aligned}

7

Practice

1

For the system x′=2y,  y′=x−y\xvar{x'} = 2\yvar{y}, \; \yvar{y'} = \xvar{x} - \yvar{y} starting at (1,3)(1, 3), use one step of Euler's method with step size h=0.1h = 0.1 to estimate (x,y)(\xvar{x}, \yvar{y}) after 0.10.1 seconds.

At (1,3)(1, 3), what are the two velocity components x′\xvar{x'} and y′\yvar{y'} before either coordinate moves?

Both rates at (1,3)(1, 3)
x′=2(3)=6y′=1−3=−2\displaystyle \begin{aligned} \xvar{x'} &= 2(3) = \xvar{6} \\ \yvar{y'} &= 1 - 3 = \yvar{-2} \end{aligned}
(Watch out: use the starting coordinate x=1\xvar{x} = 1 in y′=x−y\yvar{y'} = \xvar{x} - \yvar{y}; plugging in the new x=1.6\xvar{x} = 1.6 gives y′=−1.4\yvar{y'} = -1.4 and the wrong value y=2.86\yvar{y} = 2.86.)
Step to t=0.1t = 0.1
x=1+6(0.1)=1+0.6=1.6y=3+(−2)(0.1)=3−0.2=2.8\displaystyle \begin{aligned} \xvar{x} &= 1 + \xvar{6}(0.1) = 1 + 0.6 = 1.6 \\ \yvar{y} &= 3 + (\yvar{-2})(0.1) = 3 - 0.2 = 2.8 \end{aligned}
2

For the system x′=x−y,  y′=t+2x\xvar{x'} = \xvar{x} - \yvar{y}, \; \yvar{y'} = t + 2\xvar{x} with initial values x(0)=2\xvar{x(0)} = 2 and y(0)=1\yvar{y(0)} = 1, use Euler's method with step size h=0.1h = 0.1 to estimate x(0.2)\xvar{x(0.2)} and y(0.2)\yvar{y(0.2)}.

Each 0.10.1-second step needs a new pair of rates (x′,y′)(\xvar{x'}, \yvar{y'}); when you find y′\yvar{y'} at the start of the second step, what is tt?

Step 1 rates at t=0, x=2, y=1t = 0, \, \xvar{x} = 2, \, \yvar{y} = 1
x′=2−1=1y′=0+2(2)=0+4=4\displaystyle \begin{aligned} \xvar{x'} &= 2 - 1 = \xvar{1} \\ \yvar{y'} &= 0 + 2(2) = 0 + 4 = \yvar{4} \end{aligned}
Step 1 values at t=0.1t = 0.1
x(0.1)=2+1(0.1)=2+0.1=2.1y(0.1)=1+4(0.1)=1+0.4=1.4\displaystyle \begin{aligned} \xvar{x(0.1)} &= 2 + \xvar{1}(0.1) = 2 + 0.1 = 2.1 \\ \yvar{y(0.1)} &= 1 + \yvar{4}(0.1) = 1 + 0.4 = 1.4 \end{aligned}
Step 2 rates at t=0.1, x=2.1, y=1.4t = 0.1, \, \xvar{x} = 2.1, \, \yvar{y} = 1.4 (Watch out: update time to t=0.1t = 0.1 in y′=t+2x\yvar{y'} = t + 2\xvar{x}; leaving t=0t = 0 gives y′=4.2\yvar{y'} = 4.2 and the wrong value y(0.2)=1.82\yvar{y(0.2)} = 1.82.)
x′=2.1−1.4=0.7y′=0.1+2(2.1)=0.1+4.2=4.3\displaystyle \begin{aligned} \xvar{x'} &= 2.1 - 1.4 = \xvar{0.7} \\ \yvar{y'} &= 0.1 + 2(2.1) = 0.1 + 4.2 = \yvar{4.3} \end{aligned}
Step 2 values at t=0.2t = 0.2
x(0.2)=2.1+0.7(0.1)=2.1+0.07=2.17y(0.2)=1.4+4.3(0.1)=1.4+0.43=1.83\displaystyle \begin{aligned} \xvar{x(0.2)} &= 2.1 + \xvar{0.7}(0.1) \\ &= 2.1 + 0.07 = 2.17 \\ \yvar{y(0.2)} &= 1.4 + \yvar{4.3}(0.1) \\ &= 1.4 + 0.43 = 1.83 \end{aligned}
3

Rewrite the second-order equation y′′=−4y−y′\acc{y''} = -4\pos{y} - \vel{y'} with initial conditions y(0)=2\pos{y(0)} = 2 and y′(0)=0\vel{y'(0)} = 0 as a first-order system for position y\pos{y} and velocity v=y′\vel{v} = \vel{y'}, then use two steps of Euler's method with h=0.1h = 0.1 to estimate y(0.2)\pos{y(0.2)} and v(0.2)\vel{v(0.2)}.

With v=y′\vel{v} = \vel{y'}, write the rate of change y′\vel{y'} and the acceleration v′=y′′\acc{v'} = \acc{y''} in terms of y\pos{y} and v\vel{v}.

First-order system
y′=v,y(0)=2v′=−4y−v,v(0)=0\displaystyle \begin{aligned} \vel{y'} &= \vel{v}, & \pos{y(0)} &= 2 \\ \acc{v'} &= -4\pos{y} - \vel{v}, & \vel{v(0)} &= 0 \end{aligned}
Step 1 rates at t=0, y=2, v=0t = 0, \, \pos{y} = 2, \, \vel{v} = 0
y′=0v′=−4(2)−0=−8−0=−8\displaystyle \begin{aligned} \vel{y'} &= \vel{0} \\ \acc{v'} &= -4(2) - 0 = -8 - 0 = \acc{-8} \end{aligned}
Step 1 values at t=0.1t = 0.1 (Watch out: step y\pos{y} using the starting velocity v(0)=0\vel{v(0)} = 0 so y(0.1)=2\pos{y(0.1)} = 2; using the new velocity on each step, starting with v(0.1)=−0.8\vel{v(0.1)} = -0.8 on the first step, gives y(0.1)=1.92\pos{y(0.1)} = 1.92 and the wrong final values y(0.2)=1.7712, v(0.2)=−1.488\pos{y(0.2)} = 1.7712, \, \vel{v(0.2)} = -1.488.)
y(0.1)=2+0(0.1)=2+0=2v(0.1)=0+(−8)(0.1)=0−0.8=−0.8\displaystyle \begin{aligned} \pos{y(0.1)} &= 2 + \vel{0}(0.1) \\ &= 2 + 0 = 2 \\ \vel{v(0.1)} &= 0 + (\acc{-8})(0.1) \\ &= 0 - 0.8 = -0.8 \end{aligned}
Step 2 rates at t=0.1, y=2, v=−0.8t = 0.1, \, \pos{y} = 2, \, \vel{v} = -0.8
y′=−0.8v′=−4(2)−(−0.8)=−8+0.8=−7.2\displaystyle \begin{aligned} \vel{y'} &= \vel{-0.8} \\ \acc{v'} &= -4(2) - (-0.8) \\ &= -8 + 0.8 = \acc{-7.2} \end{aligned}
Step 2 values at t=0.2t = 0.2
y(0.2)=2+(−0.8)(0.1)=2−0.08=1.92v(0.2)=−0.8+(−7.2)(0.1)=−0.8−0.72=−1.52\displaystyle \begin{aligned} \pos{y(0.2)} &= 2 + (\vel{-0.8})(0.1) \\ &= 2 - 0.08 = 1.92 \\ \vel{v(0.2)} &= -0.8 + (\acc{-7.2})(0.1) \\ &= -0.8 - 0.72 = -1.52 \end{aligned}
4

For the system x′=x+2y,  y′=t−y\xvar{x'} = \xvar{x} + 2\yvar{y}, \; \yvar{y'} = t - \yvar{y} starting at t=0,  x=1,  y=1t = 0, \; \xvar{x} = 1, \; \yvar{y} = 1, use one step of Improved Euler's method with step size h=0.2h = 0.2 to estimate x(0.2)\xvar{x(0.2)} and y(0.2)\yvar{y(0.2)}.

After finding the starting slopes (x1′,y1′)(\xvar{x'_1}, \yvar{y'_1}), where does a trial Euler step of size h=0.2h = 0.2 move tt, x\xvar{x}, and y\yvar{y}?

Starting slopes at t=0, x=1, y=1t = 0, \, \xvar{x} = 1, \, \yvar{y} = 1
x1′=1+2(1)=1+2=3y1′=0−1=−1\displaystyle \begin{aligned} \xvar{x'_1} &= 1 + 2(1) = 1 + 2 = \xvar{3} \\ \yvar{y'_1} &= 0 - 1 = \yvar{-1} \end{aligned}
Trial point at t=0.2t = 0.2
Trial x=1+3(0.2)=1+0.6=1.6Trial y=1+(−1)(0.2)=1−0.2=0.8\displaystyle \begin{aligned} \text{Trial } \xvar{x} &= 1 + \xvar{3}(0.2) \\ &= 1 + 0.6 = 1.6 \\ \text{Trial } \yvar{y} &= 1 + (\yvar{-1})(0.2) \\ &= 1 - 0.2 = 0.8 \end{aligned}
Trial slopes at t=0.2, x=1.6, y=0.8t = 0.2, \, \xvar{x} = 1.6, \, \yvar{y} = 0.8 (Watch out: update time to t=0.2t = 0.2 in y′=t−y\yvar{y'} = t - \yvar{y} at the trial point; leaving t=0t = 0 gives y2′=−0.8\yvar{y'_2} = -0.8 and the wrong value y(0.2)=0.82\yvar{y(0.2)} = 0.82.)
x2′=1.6+2(0.8)=1.6+1.6=3.2y2′=0.2−0.8=−0.6\displaystyle \begin{aligned} \xvar{x'_2} &= 1.6 + 2(0.8) \\ &= 1.6 + 1.6 = \xvar{3.2} \\ \yvar{y'_2} &= 0.2 - 0.8 = \yvar{-0.6} \end{aligned}
Average slopes and real step from (1,1)(1, 1) (Watch out: take the real step from the starting point (1,1)(1, 1), not from the trial point (1.6,0.8)(1.6, 0.8), which would give 2.222.22 and 0.640.64.)
Average x rate=3+3.22=6.22=3.1Average y rate=−1+(−0.6)2=−1.62=−0.8x(0.2)=1+3.1(0.2)=1+0.62=1.62y(0.2)=1+(−0.8)(0.2)=1−0.16=0.84\displaystyle \begin{aligned} \text{Average } \xvar{x\text{ rate}} &= \frac{\xvar{3} + \xvar{3.2}}{2} \\ &= \frac{6.2}{2} = \xvar{3.1} \\ \text{Average } \yvar{y\text{ rate}} &= \frac{\yvar{-1} + (\yvar{-0.6})}{2} \\ &= \frac{-1.6}{2} = \yvar{-0.8} \\ \xvar{x(0.2)} &= 1 + \xvar{3.1}(0.2) \\ &= 1 + 0.62 = 1.62 \\ \yvar{y(0.2)} &= 1 + (\yvar{-0.8})(0.2) \\ &= 1 - 0.16 = 0.84 \end{aligned}
5

For the system x′=y,  y′=3x\xvar{x'} = \yvar{y}, \; \yvar{y'} = 3\xvar{x} starting at x(0)=1,  y(0)=0\xvar{x(0)} = 1, \; \yvar{y(0)} = 0, use one step of RK4 with step size h=0.2h = 0.2 to find the four slope pairs and estimate x(0.2)\xvar{x(0.2)} and y(0.2)\yvar{y(0.2)}.

What is the half-step size h2\tfrac{h}{2} used from (1,0)(1, 0) for the two midpoint stages, and which slope pair moves you by the full step h=0.2h = 0.2 to the fourth stage?

Stage 1 slopes at (1,0)(1, 0)
k1x=0k1y=3(1)=3\displaystyle \begin{aligned} \xvar{k_{1x}} &= \xvar{0} \\ \yvar{k_{1y}} &= 3(1) = \yvar{3} \end{aligned}
Stage 2 slopes after a half-step h2=0.1\tfrac{h}{2} = 0.1 from (1,0)(1, 0)
Test x=1+0.1(0)=1+0=1,Test y=0+0.1(3)=0+0.3=0.3k2x=0.3,k2y=3(1)=3\displaystyle \begin{aligned} \text{Test } \xvar{x} &= 1 + 0.1(\xvar{0}) \\ &= 1 + 0 = 1, \\ \text{Test } \yvar{y} &= 0 + 0.1(\yvar{3}) \\ &= 0 + 0.3 = 0.3 \\ \xvar{k_{2x}} &= \xvar{0.3}, \\ \yvar{k_{2y}} &= 3(1) = \yvar{3} \end{aligned}
Stage 3 slopes after a half-step h2=0.1\tfrac{h}{2} = 0.1 from (1,0)(1, 0) using (k2x,k2y)(\xvar{k_{2x}}, \yvar{k_{2y}}) (Watch out: step by h2=0.1\tfrac{h}{2} = 0.1 from the original starting point (1,0)(1, 0), not from the previous midpoint (1,0.3)(1, 0.3), which would give Test y=0.6\text{Test } \yvar{y} = 0.6, k3x=0.6\xvar{k_{3x}} = 0.6, and the wrong values x(0.2)=1.0806, y(0.2)=0.618\xvar{x(0.2)} = 1.0806, \, \yvar{y(0.2)} = 0.618.)
Test x=1+0.1(0.3)=1+0.03=1.03,Test y=0+0.1(3)=0+0.3=0.3k3x=0.3,k3y=3(1.03)=3.09\displaystyle \begin{aligned} \text{Test } \xvar{x} &= 1 + 0.1(\xvar{0.3}) \\ &= 1 + 0.03 = 1.03, \\ \text{Test } \yvar{y} &= 0 + 0.1(\yvar{3}) \\ &= 0 + 0.3 = 0.3 \\ \xvar{k_{3x}} &= \xvar{0.3}, \\ \yvar{k_{3y}} &= 3(1.03) = \yvar{3.09} \end{aligned}
Stage 4 slopes after a full step h=0.2h = 0.2 from (1,0)(1, 0) using (k3x,k3y)(\xvar{k_{3x}}, \yvar{k_{3y}})
Test x=1+0.2(0.3)=1+0.06=1.06,Test y=0+0.2(3.09)=0+0.618=0.618k4x=0.618,k4y=3(1.06)=3.18\displaystyle \begin{aligned} \text{Test } \xvar{x} &= 1 + 0.2(\xvar{0.3}) \\ &= 1 + 0.06 = 1.06, \\ \text{Test } \yvar{y} &= 0 + 0.2(\yvar{3.09}) \\ &= 0 + 0.618 = 0.618 \\ \xvar{k_{4x}} &= \xvar{0.618}, \\ \yvar{k_{4y}} &= 3(1.06) = \yvar{3.18} \end{aligned}
Weighted average slopes and final step from (1,0)(1, 0)
Average x rate=0+2(0.3)+2(0.3)+0.6186=1.8186=0.303Average y rate=3+2(3)+2(3.09)+3.186=18.366=3.06x(0.2)=1+0.303(0.2)=1+0.0606=1.0606y(0.2)=0+3.06(0.2)=0+0.612=0.612\displaystyle \begin{aligned} &\text{Average } \xvar{x\text{ rate}} \\ &\quad = \frac{\xvar{0} + 2(\xvar{0.3}) + 2(\xvar{0.3}) + \xvar{0.618}}{6} \\ &\quad = \frac{1.818}{6} = \xvar{0.303} \\ &\text{Average } \yvar{y\text{ rate}} \\ &\quad = \frac{\yvar{3} + 2(\yvar{3}) + 2(\yvar{3.09}) + \yvar{3.18}}{6} \\ &\quad = \frac{18.36}{6} = \yvar{3.06} \\ &\xvar{x(0.2)} = 1 + \xvar{0.303}(0.2) \\ &\quad = 1 + 0.0606 = 1.0606 \\ &\yvar{y(0.2)} = 0 + \yvar{3.06}(0.2) \\ &\quad = 0 + 0.612 = 0.612 \end{aligned}