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) and y(t) go over time step by step.
1
Following Arrows in the Phase Plane
Given the system
x′=y,y′=−x
and a starting point (1,0), we want to track the path of the point (x,y) in the x-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=Old Value+(Rate of Change)×(Time Step)
When two variables change together, the system tells us both components of our velocity arrow at the current point.
Following Arrows in the Phase Plane
Because x′ is the horizontal speed and 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 xNew y=Old x+(x’s rate)×(step)=Old y+(y’s rate)×(step)
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 t. For the system
x′=x+y,y′=2t−x
starting at t=0,x=1,y=2, we want to estimate x and y at t=0.2 using Euler's method with step size h=0.1.
Euler's Method on a System
Text solution
Both rates at t=0Plug the starting values t=0,x=1,y=2 into both equations before moving either variable.
x′y′=1+2=3=2(0)−1=0−1=−1
First step to t=0.1Step x and y forward together by h=0.1 using those starting rates.
New xNew y=1+(3)(0.1)=1+0.3=1.3=2+(−1)(0.1)=2−0.1=1.9
Both rates at t=0.1Plug the new values t=0.1,x=1.3,y=1.9 into both equations to find the next pair of rates.
x′y′=1.3+1.9=3.2=2(0.1)−1.3=0.2−1.3=−1.1
Second step to t=0.2Step both variables forward together by h=0.1 to reach t=0.2.
New xNew y=1.3+(3.2)(0.1)=1.3+0.32=1.62=1.9+(−1.1)(0.1)=1.9−0.11=1.79
So after two steps, at t=0.2, Euler's method estimates x=1.62 and y=1.79.
You might also see this rule written with subscripts, where n marks the values at the start of the step:
Euler's method needs first-order rates of change, so what do we do when a physics problem gives us acceleration y′′ instead? For the damped spring equation
y′′=−2y−3y′
starting at t=0 with position y=1 and velocity y′=0, we want to estimate the position and velocity at t=0.2 using step size h=0.1.
Turning a Second-Order Equation into a System
Text solution
Rewrite as a first-order systemName velocity v=y′ so that position's rate of change is v and velocity's rate of change is the acceleration y′′.
y′v′=v=−2y−3v
Both rates at t=0Plug the starting position y=1 and starting velocity v=0 into both equations.
y′v′=0=−2(1)−3(0)=−2−0=−2
First step to t=0.1Step position y and velocity v forward together by h=0.1.
New yNew v=1+(0)(0.1)=1+0=1=0+(−2)(0.1)=0−0.2=−0.2
Both rates at t=0.1Plug the new position y=1 and velocity v=−0.2 into both equations.
y′v′=−0.2=−2(1)−3(−0.2)=−2+0.6=−1.4
Second step to t=0.2Step both position and velocity forward by h=0.1 to reach t=0.2.
New yNew v=1+(−0.2)(0.1)=1−0.02=0.98=−0.2+(−1.4)(0.1)=−0.2−0.14=−0.34
So at t=0.2, Euler's method estimates position y=0.98 and velocity v=−0.34. Notice that the estimated position stayed at 1 during the first step because that step uses the starting velocity, 0, and only started moving downward on the second step once the velocity was no longer 0.
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) on the circle system
x′=y,y′=−x
we want to take a step of size h=0.1 that curves with the circle instead of spiraling outward.
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
Text solution
Starting slopes at (1,0)Find both velocity components at the starting point (1,0).
x1′y1′=0=−1
Trial step to the end of the intervalStep both x and y forward by h=0.1 using the starting slopes to reach the trial point.
Trial slopes at (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′y2′=−0.1=−1
Average both pairs of slopesAverage the starting rate and trial rate for x, and do the same for y.
Average x rateAverage y rate=20+(−0.1)=−0.05=2−1+(−1)=−1
Real step from (1,0)Go back to the starting point (1,0) and step forward by h=0.1 using the average rates.
New xNew y=1+(−0.05)(0.1)=1−0.005=0.995=0+(−1)(0.1)=0−0.1=−0.1
Averaging with the inward-tilted arrow at the trial point pulls x inward from 1 to 0.995. The exact solution is x=cost,y=−sint, so the true value at t=0.1 is x=cos(0.1)≈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 t also appears in the system. For our earlier system
x′=x+y,y′=2t−x
starting at t=0,x=1,y=2, we want to estimate x(0.1) and y(0.1) with step size h=0.1.
Stepping a System with Improved Euler
x′=x+y,y′=2t−x
Improved Euler,h=0.1
t00.1x1?y2?
Text solution
Starting slopes at t=0Plug t=0,x=1,y=2 into both equations.
x1′y1′=1+2=3=2(0)−1=0−1=−1
Trial step to t=0.1Step t,x, and y forward together by h=0.1 using the starting slopes.
Trial slopes at the trial pointPlug Trial t=0.1,Trial x=1.3,Trial y=1.9 into both equations.
x2′y2′=1.3+1.9=3.2=2(0.1)−1.3=0.2−1.3=−1.1
Average both pairs of slopesAverage the starting slope and trial slope for each variable.
Average x rateAverage y rate=23+3.2=26.2=3.1=2−1+(−1.1)=2−2.1=−1.05
Real step from (1,2)Go back to the starting point (1,2) and step forward by h=0.1 using the average rates.
New xNew y=1+(3.1)(0.1)=1+0.31=1.31=2+(−1.05)(0.1)=2−0.105=1.895
So at t=0.1, Improved Euler estimates x=1.31 and y=1.895, improving on the basic Euler estimate (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 2h and to the endpoint at h, then combine the four slopes with weights 1,2,2,1.
RK4 on a System
At every stage of RK4, we step both variables from the original point (Old x,Old y) before finding the next slope pair, and t moves along with them, to Old t+2h at both midpoints and Old t+h at the endpoint:
Starting slopes (k1x,k1y): Plug the starting point into both equations.
First midpoint slopes (k2x,k2y): Step both variables from the start by 2h using (k1x,k1y),
(Old x+2hk1x,Old y+2hk1y)
and plug that midpoint into both equations.
Second midpoint slopes (k3x,k3y): Go back to the start, step both variables by 2h using (k2x,k2y),
(Old x+2hk2x,Old y+2hk2y)
and plug that new midpoint into both equations.
End-of-step slopes (k4x,k4y): Go back to the start, step both variables a full h using (k3x,k3y),
(Old x+hk3x,Old y+hk3y)
and plug that endpoint into both equations.
Real step using 1,2,2,1 weights: Average the four x slopes and the four y slopes to step from the starting point:
New x=Old x+h⋅weighted average x rate6k1x+2k2x+2k3x+k4xNew y=Old y+h⋅weighted average y rate6k1y+2k2y+2k3y+k4y
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, step x and y directly without introducing any extra variable. Only when an equation has a second derivative y′′, such as y′′=−2y−3y′, do you introduce velocity v=y′ to turn it into the first-order system y′=v,v′=−2y−3v.
Euler's method (one slope pair per step)
Find (x′,y′) at the start of the step and step both variables together:
New xNew y=Old x+(x’s rate)h,=Old y+(y’s rate)h
For x′=x+y,y′=2t−x at (0,1,2) with h=0.1, finding x′=3 and y′=−1 before moving gives x(0.1)=1+3(0.1)=1.3 and y(0.1)=2+(−1)(0.1)=1.9. Basic Euler is quick for rough steps, but on curved phase-plane paths like x′=y,y′=−x it walks straight along tangents and spirals outward.
Improved Euler (two slope pairs per step)
Use the starting slopes (x1′,y1′) to take a trial step of size h for t,x, and y together, find the trial slopes (x2′,y2′) there, and step from the original starting point using the average rates 2x1′+x2′ and 2y1′+y2′. On x′=y,y′=−x from (1,0), averaging (0,−1) at the start with (−0.1,−1) at the trial point (1,−0.1) gives average rates (−0.05,−1) and pulls the step inward to (0.995,−0.1).
RK4 (four slope pairs per step)
Find (k1x,k1y) at the start, step from the start by 2h to find (k2x,k2y), step from the start by 2h again with k2 to find (k3x,k3y), and step from the start by h with k3 to find (k4x,k4y). Then step from the original starting point using the 1,2,2,1 weighted averages:
Rewrite the second-order equation y′′=−4y−y′ with initial conditions y(0)=2 and y′(0)=0 as a first-order system for position y and velocity v=y′, then use two steps of Euler's method with h=0.1 to estimate y(0.2) and v(0.2).
With v=y′, write the rate of change y′ and the acceleration v′=y′′ in terms of y and v.
First-order system
y′v′=v,=−4y−v,y(0)v(0)=2=0
Step 1 rates at t=0,y=2,v=0
y′v′=0=−4(2)−0=−8−0=−8
Step 1 values at t=0.1(Watch out: step y using the starting velocity v(0)=0 so y(0.1)=2; using the new velocity on each step, starting with v(0.1)=−0.8 on the first step, gives y(0.1)=1.92 and the wrong final values y(0.2)=1.7712,v(0.2)=−1.488.)
Trial slopes at t=0.2,x=1.6,y=0.8(Watch out: update time to t=0.2 in y′=t−y at the trial point; leaving t=0 gives y2′=−0.8 and the wrong value y(0.2)=0.82.)
x2′y2′=1.6+2(0.8)=1.6+1.6=3.2=0.2−0.8=−0.6
Average slopes and real step from (1,1)(Watch out: take the real step from the starting point (1,1), not from the trial point (1.6,0.8), which would give 2.22 and 0.64.)
Average x rateAverage y ratex(0.2)y(0.2)=23+3.2=26.2=3.1=2−1+(−0.6)=2−1.6=−0.8=1+3.1(0.2)=1+0.62=1.62=1+(−0.8)(0.2)=1−0.16=0.84
5
For the system x′=y,y′=3x starting at x(0)=1,y(0)=0, use one step of RK4 with step size h=0.2 to find the four slope pairs and estimate x(0.2) and y(0.2).
What is the half-step size 2h used from (1,0) for the two midpoint stages, and which slope pair moves you by the full step h=0.2 to the fourth stage?
Stage 1 slopes at (1,0)
k1xk1y=0=3(1)=3
Stage 2 slopes after a half-step 2h=0.1 from (1,0)
Test xTest yk2xk2y=1+0.1(0)=1+0=1,=0+0.1(3)=0+0.3=0.3=0.3,=3(1)=3
Stage 3 slopes after a half-step 2h=0.1 from (1,0) using (k2x,k2y)(Watch out: step by 2h=0.1 from the original starting point (1,0), not from the previous midpoint (1,0.3), which would give Test y=0.6,k3x=0.6, and the wrong values x(0.2)=1.0806,y(0.2)=0.618.)
Test xTest yk3xk3y=1+0.1(0.3)=1+0.03=1.03,=0+0.1(3)=0+0.3=0.3=0.3,=3(1.03)=3.09
Stage 4 slopes after a full step h=0.2 from (1,0) using (k3x,k3y)
Test xTest yk4xk4y=1+0.2(0.3)=1+0.06=1.06,=0+0.2(3.09)=0+0.618=0.618=0.618,=3(1.06)=3.18
Weighted average slopes and final step from (1,0)
Average x rate=60+2(0.3)+2(0.3)+0.618=61.818=0.303Average y rate=63+2(3)+2(3.09)+3.18=618.36=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