Lotka Volterra Simulation

Overview


The basic Lotka Volterra Model
{% \frac{dx}{dt} = x(\lambda - by) %}
{% \frac{dy}{dt} = y(-\mu + cx) %}
can easilty be simulated in code

Discrete Time Phase Space Solutions



let population = { x: 100, y:100 }

function next(population, lambda, b, mu, c, dt){
  let dxdt = population.x*(lambda - b*population.y);
  let dydt = population.y*(-1*mu + c*population.x);
  let dx = dxdt * dt;
  let dy = dydt * dt;
  return {
    x:population.x + dx,
    y:population.y + dy
  };
}

let lambda = 0.05;
let b = 0.02;
let mu = 0.05;
let c = 0.01;
let dt = 0.01;
let values = [population];
$range(1,1000).forEach(p=>{
  values.push(next(values[values.length-1], lambda, b, mu, c, dt));
});
					
Try it!

Contents