# Math Insight

### Applet: Modifying the Euler approximation to a pure time differential equation

Illustration of modifications of Euler algorithm to estimate the solution to a pure time differential equation $\diff{y}{t}=f(t)$ with initial condition $y(t_0)=y_0$. The function $f(t)$ is plotted by the blue curve in the left panel. Like the forward and backward Euler algorithms, the function $f(t)$ is approximated as though it were constant on intervals of length $\Delta t$, as illustrated by the horizontal length segments coming from the graph of $f$. In this modification, the height of each line segment is determined by the value of $f(t)$ at a fraction $p$ from the left of the interval (green dots). In this way, $p=0$ corresponds to Forward Euler and $p=1$ corresponds to Backward Euler. When we assume $f(t)$ is a constant, the solution to $\diff{y}{t}=f(t)$ is a line whose slope is the value of $f$. The approximate solution is illustrated by the green curve in the right panel. Each segment of the green curve has a slope given by the height of the corresponding line segment in the left panel. To see this correspondence, you can move the pink points in either panel. The matching segments of the approximated $f(t)$ (at left) and estimate of $y(t)$ (at right) are highlighted in pink. Gray lines emphasize how we are are viewing $y(t)$ as a line with slope given by the constant value of $f(t)$.

The calculation for the value of $y(t)$ at the end of the highlighted segment is shown in the upper right corner, which is based on the equation for a line with slope $f$. The estimate of the value of $y$ at the pink point is also shown.

If you check the “exact” box, the exact solution computed by the antiderivative is $f$ is shown in red (assuming $f(t)$ is simple enough for its antiderivative to be computed). In addition, the exact value of $y(t)$ at the position of the pink point is displayed along with the error between the approximate and exact values. Clearing the “details” box hides the points indicating the endpoints, as well as the line segments and pink point in the left panel. This view reduces the clutter when $\Delta t$ is small and the number of segments is large.

You can change the function $f(t)$ and other parameters by typing values in the corresponding boxes. You can also change the initial condition $y_0$ by dragging the blue point in the right panel.

Applet file: modifying_euler_pure_time.ggb