When the Slope Depends on Time and the Solution
A differential equation may specify a rate of change using both the current time and the current value of the quantity being modeled. For example, a population's growth rate might change with the season as well as with the population size. In that situation, a slope is not determined by the solution value alone: the time at which that value occurs matters too.
Forward Euler handles this by evaluating the slope at the current time-value pair, then using that slope to estimate the next value. The key habit is to update both coordinates together. At each step, use the time and approximate solution value that belong to that step.
The Forward Euler Rule for This Setting
Suppose an initial value is given at time \(t_0\), with \(y(t_0)=y_0\), and choose a step size \(h>0\). The time values are \(t_n=t_0+nh\). Starting with the approximate value \(y_0\), calculate each next value using the slope at the current pair \((t_n,y_n)\):
The function is evaluated at \(t_n\) and \(y_n\), not at the next time or the next approximate value. Once the calculation gives \(y_{n+1}\), that value becomes the current approximate value for the following step. The new time \(t_{n+1}\) becomes the time used in that next slope evaluation.
The method can be carried out for a finite number of steps provided \(f(t_n,y_n)\) is defined at every pair where it is evaluated. Keep track of the units as well: if \(t\) is measured in hours and \(y\) in liters, then \(f(t,y)\) has units of liters per hour, and multiplying by a step in hours gives a change in liters.
Why the Update Uses the Current Slope
The rule follows from the meaning of a derivative. Suppose a solution \(y(t)\) passes through \((t_n,y(t_n))\) and satisfies \(y'=f(t,y)\). At that point its instantaneous slope is \(f(t_n,y(t_n))\). A small time increase \(h\) is approximated by moving along the tangent line at that point.
In a numerical calculation, the exact value \(y(t_n)\) is generally not known after the initial time. Euler therefore substitutes its current estimate \(y_n\) into the slope rule. This gives \(y_{n+1}=y_n+h f(t_n,y_n)\). The next slope is evaluated at the new estimated point because that is now the point from which the following tangent-line step begins.
Worked Example: A Slope That Adds Time and Solution Value
Worked Example: A Slope That Adds Time and Solution Value
Use forward Euler with \(h=0.5\) to approximate the solution of \(y'=t+y\), \(y(0)=1\), at \(t=1\). The rule is \(f(t,y)=t+y\). There are two steps because \(1=0+2(0.5)\).
At the initial pair, \(t_0=0\) and \(y_0=1\). The first slope is \(f(t_0,y_0)=f(0,1)=0+1=1\). Thus \(y_1=1+0.5(1)=1.5\), and \(t_1=0+0.5=0.5\).
For the second step, evaluate at the current pair \((t_1,y_1)=(0.5,1.5)\): \(f(t_1,y_1)=f(0.5,1.5)=0.5+1.5=2\). Therefore \(y_2=1.5+0.5(2)=2.5\), and \(t_2=0.5+0.5=1\).
The approximation at \(t=1\) is \(y_2=2.5\). Check the two updates: \(1+0.5f(0,1)=1+0.5(1)=1.5=y_1\), and \(1.5+0.5f(0.5,1.5)=1.5+0.5(2)=2.5=y_2\).
Worked Example: A Time-Varying Factor
Worked Example: A Time-Varying Factor
Apply two forward Euler steps of size \(h=0.25\) to \(y'=t(2-y)\), with \(y(1)=0\). Here the slope depends on time through the factor \(t\), and it depends on the solution through \(2-y\). Find the approximation at \(t=1.5\).
The starting pair is \(t_0=1\), \(y_0=0\). The first slope is \(f(1,0)=1(2-0)=2\). The value change is \(0.25(2)=0.5\), so \(y_1=0+0.5=0.5\); the next time is \(t_1=1+0.25=1.25\).
At \((1.25,0.5)\), the next slope is \(f(1.25,0.5)=1.25(2-0.5)=1.25(1.5)=1.875\). The value change is \(0.25(1.875)=0.46875\), so \(y_2=0.5+0.46875=0.96875\). The next time is \(t_2=1.25+0.25=1.5\).
Thus the Euler approximation at \(t=1.5\) is \(0.96875\). Checking the recurrence gives \(y_1=0+0.25(2)=0.5\) and \(y_2=0.5+0.25(1.875)=0.96875\), as calculated.
Worked Example: Keeping the Time and Value Columns Aligned
Worked Example: Keeping the Time and Value Columns Aligned
Use \(h=0.5\) to approximate the solution of \(y'=t^2-y\), \(y(0)=2\), through \(t=1.5\). The slope function is \(f(t,y)=t^2-y\), and the target requires three steps.
Step 0 starts at \((t_0,y_0)=(0,2)\). The slope is \(f(0,2)=0^2-2=-2\). Hence \(y_1=2+0.5(-2)=1\), at time \(t_1=0.5\).
At step 1, use the pair \((0.5,1)\). The slope is \(f(0.5,1)=(0.5)^2-1=0.25-1=-0.75\). Thus \(y_2=1+0.5(-0.75)=1-0.375=0.625\), at time \(t_2=1\).
At step 2, use \((1,0.625)\). The slope is \(f(1,0.625)=1^2-0.625=0.375\). Thus \(y_3=0.625+0.5(0.375)=0.625+0.1875=0.8125\), at time \(t_3=1.5\).
The approximation at \(t=1.5\) is \(0.8125\). The recurrence checks directly: \(2+0.5(-2)=1\), \(1+0.5(-0.75)=0.625\), and \(0.625+0.5(0.375)=0.8125\). Each slope used the time and value from the same row.
A Reliable Step-by-Step Routine
A short routine helps prevent mix-ups, especially when the slope expression includes several occurrences of \(t\) and \(y\). At each step, treat the current pair as one input to the function \(f\).
Write down \(t_n\) and \(y_n\) before evaluating the slope.
Substitute \(t_n\) for every \(t\) and \(y_n\) for every \(y\) in \(f(t,y)\).
Calculate \(y_{n+1}=y_n+h f(t_n,y_n)\).
Calculate \(t_{n+1}=t_n+h\), then use the new pair on the next step.
Common Mistake: Using the Wrong Time in the Next Slope
Return to \(y'=t+y\), \(y(0)=1\), \(h=0.5\). The first step gives \(y_1=1.5\) at \(t_1=0.5\). A mistaken second step might keep using \(t=0\), calculate \(f(0,1.5)=1.5\), and report
The arithmetic is consistent with that calculation, but the slope was evaluated at the wrong time. The second step starts at \(t_1=0.5\), so its correct slope is \(f(0.5,1.5)=2\). The correct update is
A related error is to substitute the proposed next value \(y_{n+1}\) into the slope for the same step. Forward Euler does not do that: the slope for a step is evaluated using the pair at the start of that step. The newly calculated value is used only when beginning the following step.
Check Your Understanding
For each question, keep the time and approximate value from the same step together.
- For \(y'=t-y\), \(y(0)=1\), and \(h=0.5\), find the first Euler approximation and state the time at which it applies.
- For \(y'=t(1+y)\), starting from \(t=1\), \(y=1\), with \(h=0.2\), what slope is used for the first step, and what is the resulting approximate value?
- Why must the time input be updated when \(f\) depends explicitly on \(t\)?
- For \(y'=t+y\), \(y(0)=1\), and \(h=0.5\), identify the error in using \(f(0,1.5)\) for the second step.
- Write the general forward Euler updates for \(y'=f(t,y)\) and explain which pair is used to evaluate the slope at step \(n\).