Tutorials › Calculus I › Euler’s Method on a Nonuniform Grid

Euler's Method and Numerical Solutions · Tutorial 1426 of 1495

Euler's Method on a Nonuniform Grid

Use a separate step length at each iteration of the forward Euler method, keeping the time grid and solution values consistent.

Advanced 10 min read

What You'll Learn

  • Define a nonuniform time grid using a different step length at each iteration.
  • Apply the forward Euler update with the current step length.
  • Evaluate time-dependent slopes at the correct current time.
  • Organize nonuniform Euler calculations in a table.
  • Detect errors caused by reusing a step length or misaligning times and values.

Why Use a Nonuniform Grid?

A forward Euler calculation does not have to use equally spaced times. A problem may call for larger steps in one part of an interval and smaller steps in another, or the available time points may already be unevenly spaced. The essential bookkeeping is to record the current time and the current approximate solution together, then use the length of the next step in the update.

For a uniform grid, one step length is reused throughout the calculation. On a nonuniform grid, each step has its own length. This changes the arithmetic at each iteration, but not the basic Euler procedure: evaluate the slope at the current point, multiply by the step length, and add that increment to the current solution value.

Definition and Update Rule

Consider the initial-value problem \(y'=f(t,y)\), with \(y(t_0)=y_0\). A nonuniform grid is a sequence of time values \(t_0,t_1,\ldots,t_N\) whose consecutive differences need not be equal. Define the step length from \(t_n\) to \(t_{n+1}\) by \(h_n=t_{n+1}-t_n\). For a forward calculation in increasing time, each \(h_n\) is positive.

Definition: The forward Euler approximation on a nonuniform grid is the sequence defined by \(y_0\), together with $$ t_{n+1}=t_n+h_n,\qquad y_{n+1}=y_n+h_n f(t_n,y_n), $$ for \(n=0,1,\ldots,N-1\). Here \(h_n\) is the step length for that particular step, and \(f(t_n,y_n)\) is the slope evaluated at the current time and current approximate solution.

The subscript on \(h_n\) matters: the step from \(t_n\) to \(t_{n+1}\) uses \(h_n\), not a step length from another part of the grid. The slope also belongs to the current point \((t_n,y_n)\). The next time and solution value are computed together, so that each row of a calculation corresponds to one point on the grid.

If the grid is given as a list of times, calculate each step length by subtracting consecutive times. For example, if the times are \(0\), \(0.2\), and \(0.5\), then the two step lengths are \(0.2-0=0.2\) and \(0.5-0.2=0.3\). The second step does not use \(0.5\), the total elapsed time; it uses the interval from the current time \(0.2\) to the next time \(0.5\).

Why the Update Uses the Current Step Length

At a current point \((t_n,y_n)\), the differential equation supplies the slope \(f(t_n,y_n)\). Over a short interval of length \(h_n\), forward Euler estimates the change in the solution by the current slope times the interval length. The estimated change is therefore \(h_n f(t_n,y_n)\), which is added to \(y_n\).

$$ \text{estimated change in }y = \text{current slope}\times\text{length of the next interval} = f(t_n,y_n)h_n. $$

This also explains why the time must be updated by the same interval length: that is the time interval over which the slope is being used. In particular, if a time-dependent slope is \(f(t,y)\), the slope for the step beginning at \(t_n\) is evaluated using \(t_n\), not \(t_{n+1}\). The method uses the current point to estimate the change across the next interval.

Key takeaway: At each iteration, use the same \(h_n\) in both updates. Advance time by \(h_n\), and advance the solution by \(h_n\) times the slope at the current point.

A Reliable Calculation Layout

A table helps prevent the time index, solution index, and step length from drifting out of alignment. In each row, first identify the current time and solution, then evaluate the slope, then apply that row's step length to calculate the next values.

1
Record the current pair.
Start with the current grid time \(t_n\) and approximation \(y_n\).
2
Find the current slope.
Evaluate \(f(t_n,y_n)\), using the current time and current approximation.
3
Use this step's length.
Calculate \(t_{n+1}=t_n+h_n\) and \(y_{n+1}=y_n+h_n f(t_n,y_n)\).
4
Carry the new pair forward.
Use \((t_{n+1},y_{n+1})\) as the current pair for the next row, with its own step length \(h_{n+1}\).

Worked Examples

Worked Example: Increasing Step Lengths with a Time-Dependent Slope

Approximate the solution of \(y'=t+y\), \(y(0)=1\), using step lengths \(h_0=0.2\), \(h_1=0.3\), and \(h_2=0.5\). Find the approximation at the last grid time.

Initially, \(t_0=0\) and \(y_0=1\). The first slope is \(f(t_0,y_0)=t_0+y_0=0+1=1\). Thus $$ t_1=0+0.2=0.2,\qquad y_1=1+0.2(1)=1.2. $$

For the second step, use the current pair \((t_1,y_1)=(0.2,1.2)\). Its slope is \(f(t_1,y_1)=0.2+1.2=1.4\). The step length is \(h_1=0.3\), so $$ t_2=0.2+0.3=0.5,\qquad y_2=1.2+0.3(1.4)=1.2+0.42=1.62. $$

For the third step, the current pair is \((0.5,1.62)\), giving slope \(f(t_2,y_2)=0.5+1.62=2.12\). With \(h_2=0.5\), $$ t_3=0.5+0.5=1,\qquad y_3=1.62+0.5(2.12)=1.62+1.06=2.68. $$

The grid times are \(0\), \(0.2\), \(0.5\), and \(1\), and the corresponding approximations are \(1\), \(1.2\), \(1.62\), and \(2.68\). Check the updates: the three solution increments are \(0.2(1)=0.2\), \(0.3(1.4)=0.42\), and \(0.5(2.12)=1.06\). Adding them successively gives \(1.2\), \(1.62\), and \(2.68\), as calculated.

Worked Example: Nonuniform Steps for a Decay Equation

Apply forward Euler to \(y'=-2y\), \(y(0)=10\), using \(h_0=0.1\), \(h_1=0.2\), and \(h_2=0.1\). Track the time and approximate solution at every step.

At the initial point, \(t_0=0\), \(y_0=10\), and the slope is \(-2(10)=-20\). Therefore $$ t_1=0+0.1=0.1,\qquad y_1=10+0.1(-20)=10-2=8. $$

At the next point, \(t_1=0.1\), \(y_1=8\), so the slope is \(-2(8)=-16\). Use the next step length, \(h_1=0.2\): $$ t_2=0.1+0.2=0.3,\qquad y_2=8+0.2(-16)=8-3.2=4.8. $$

At \((t_2,y_2)=(0.3,4.8)\), the slope is \(-2(4.8)=-9.6\). With \(h_2=0.1\), $$ t_3=0.3+0.1=0.4,\qquad y_3=4.8+0.1(-9.6)=4.8-0.96=3.84. $$

The final approximation is \(y_3=3.84\) at \(t_3=0.4\). As a check, each new value equals the preceding value plus its computed increment: \(10-2=8\), \(8-3.2=4.8\), and \(4.8-0.96=3.84\). The time checks are \(0+0.1=0.1\), \(0.1+0.2=0.3\), and \(0.3+0.1=0.4\).

Worked Example: Recovering Step Lengths from Listed Times

Use forward Euler for \(y'=t-y\), starting from \(y(1)=2\), on the grid \(t_0=1\), \(t_1=1.25\), \(t_2=1.75\), \(t_3=2\). Find the approximation at \(t=2\).

First calculate the differences between consecutive times: $$ h_0=1.25-1=0.25,\qquad h_1=1.75-1.25=0.5,\qquad h_2=2-1.75=0.25. $$ The initial values are \(t_0=1\) and \(y_0=2\). The initial slope is \(f(1,2)=1-2=-1\). Hence $$ y_1=2+0.25(-1)=1.75. $$

At \(t_1=1.25\), the current approximation is \(y_1=1.75\). The slope is \(f(1.25,1.75)=1.25-1.75=-0.5\). Using \(h_1=0.5\), $$ y_2=1.75+0.5(-0.5)=1.75-0.25=1.5. $$

At \(t_2=1.75\), the slope is \(f(1.75,1.5)=1.75-1.5=0.25\). With \(h_2=0.25\), $$ y_3=1.5+0.25(0.25)=1.5+0.0625=1.5625. $$

The approximation at \(t=2\) is \(1.5625\). Check that the grid differences match the stated times: \(1+0.25=1.25\), \(1.25+0.5=1.75\), and \(1.75+0.25=2\). Check the solution updates using their slopes: \(2-0.25=1.75\), \(1.75-0.25=1.5\), and \(1.5+0.0625=1.5625\).

Common Mistake: Reusing One Step Length

A common error is to use the first step length for every iteration, even when the grid is nonuniform. Consider the grid in the third example. Its step lengths are \(0.25\), \(0.5\), and \(0.25\). At the second iteration, the current values are \(t_1=1.25\) and \(y_1=1.75\), and the slope is \(-0.5\).

The incorrect calculation reuses \(0.25\) and gives \(y_2=1.75+0.25(-0.5)=1.625\). But the actual next interval has length \(1.75-1.25=0.5\), so the correct update is \(y_2=1.75+0.5(-0.5)=1.5\). The incorrect value does not correspond to the listed next time \(t_2=1.75\); it uses only half of that interval's length.

Correction: Before each update, identify the current and next grid times and calculate their difference. Use that difference as the step length for both the time advance and the solution update.

What the Grid Records

A nonuniform Euler calculation is a sequence of paired values \((t_n,y_n)\). The index \(n\) identifies both the current time and its associated approximation. The step length \(h_n\) belongs to the transition from that pair to the next one, not to the point alone. Keeping these roles distinct makes it easier to audit a calculation and to locate an error.

QuantityRole in the step from \(n\) to \(n+1\)
\(t_n\)Current time at which the slope is evaluated
\(y_n\)Current approximate solution
\(f(t_n,y_n)\)Slope supplied by the differential equation at the current pair
\(h_n\)Length of the interval from \(t_n\) to \(t_{n+1}\)
\(t_{n+1},y_{n+1}\)Next time and next approximate solution

For a time-dependent equation, checking the slope evaluation is especially useful: the time argument must agree with the current row. For any equation, checking the increment is useful: it must equal the current slope multiplied by the step length in that row. These checks do not certify that an approximation is close to the exact solution; they verify that the Euler updates and grid bookkeeping have been carried out as specified.

Check Your Understanding

For each question, keep the time points, step lengths, and solution values aligned.

  1. If \(t_0=2\), \(t_1=2.3\), and \(t_2=2.8\), what are \(h_0\) and \(h_1\)?
  2. For \(y'=t+y\), at \((t_n,y_n)=(1,2)\) with \(h_n=0.4\), what slope is used and what is the next Euler value?
  3. In the nonuniform update, which step length is used to calculate \(y_{n+1}\), and at which point is the slope evaluated?
  4. What bookkeeping error occurs if a calculation uses the same step length at every iteration despite unequal grid spacing?
  5. For the grid \(0,0.2,0.7\), state the two step lengths and the final grid time.

Test yourself: Calculus I final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon