The **forward (explicit) Euler** method is a **first-order** numerical procedure for solving **ODE**s with a given initial value.

The **forward Euler **method is said to be the simplest and most obvious numerical **ODE**s integrator. In fact, the simulation using the **forward Euler** only depends on past values of state variables and state derivatives (thus, an **explicit** integration algorithm).

Let:

- be the time at the th time-step,
- be the computed solution at the th time-step,
- be the step size, , being constant here.

Then, the** forward Euler** method used for solving **ODE**s is based on the formula:

The **forward Euler** method is based on a** truncated Taylor series expansion**. Expanding in the neighbourhood of , one gets:

One can see above that the truncation of the **Taylor series** induces an error at every time-step, that is the **local truncation error**. The **local truncation error** of the **forward Euler** method is . That is to say the **forward Euler** method is a **first-order technique**.

We end up this post with 2 example codes in **R**, and **C++** both implementing the** forward Euler** method.

# Édouard Tallent @ TaGoMa.Tech # December 2012 # QuantCorner: https://quantcorner.wordpress.com # The following code implements the Forward Euler Method # Initial value problem: # dx/dy = x / y, with y(0) = 1. # Let x(0) = 0 and the step size h = 0.1. # Integrate at y(0.3) using the forward Euler method # Forward Euler method fwd.e <- function(f, x0, y0, xfinal, h){ n <- (xfinal - x0) * h x_n <- x0 y_n <- y0 while (x_n < xfinal) { x_n <- x0 + h y_n <- y0 + h * f(x0, y0) x0 <- x_n; y0 <- y_n; } return(cat("Forward Euler: ", y_n)) } # Call the fwd.e function f <- function(x, y) x / y fwd.e(f, 0, 1, 0.3, 0.1)

// Édouard Tallent @ TaGoMa.Tech // December 2012 // QuantCorner: https://quantcorner.wordpress.com // The following code implements the Forward Euler Method // Initial value problem: // dx/dy = x / y, with y(0) = 1. // Let x(0) = 0 and the step size h = 0.1. // Integrate at y(0.3) using the forward Euler method #include<iostream> #include<functional> #include<cmath> // Forward Euler method double ForwardEuler (std::function<double (double x, double y)>f, double x0, double y0, double xfinal, double h) { double n = (xfinal - x0) * h; double x_n; double y_n; do { x_n = x0 + h; y_n = y0 + h * f(x0, y0); x0 = x_n; y0 = y_n; } while (x_n <= xfinal); return y_n; } // The function to integrate double f (double x, double y) { return x / y; } // Main function int main() { double x0 = 0.0; double y0 = 1.0; double xfinal = 0.3; double h = 0.1; double res; res = ForwardEuler(f, x0, y0, xfinal, h); std::cout << "Forward Euler:\t" << res << std::endl; return 0; }