First Order - Euler Method

Overview


the Euler method is used to solve first order differential equations of a single variable. Usually, you will have an equation such as
{% y'(x) = f(x, y) %}
which says that the derivative of y is a function of x. The Euler method uses the following observation:
{% y(x+\Delta x) \approx y(x) + y'(x, y) \times \Delta x %}
Once we have a a value for y at a given x, we can easily approximate the value of y at other values of x by choosing a step size, {% \Delta x %} running the above equation forward (or backward)

Example


The following example is a classic example from epidemiology. kermack-mckendrick (SIR) model and uses the finite difference library.

{% S'(t) = -\beta S(t) I(t) %}
{% I'(t) = -\beta S(t) I(t) - \alpha I(t) %}

var fd = await import('/lib/numeric/finite-difference/v1.0.0/finite-difference.mjs');
//S, I
let boundary = [763 - 25, 25];
let beta = 0.0025;
let alpha = 0.3;
let derivative = function(values){
  return [-1*beta*values[0]*values[1], beta * values[0]*values[1] - alpha*values[1]];
}

let answer = fd.euler(boundary, derivative, 0.1, 100);
						 
Try it!

Contents