I am trying to do the Lotka-Volterra model using the Euler method but I am not getting the right graph at all. This is on Python.
I have tried changing the tstep and arrays which has improved it. I have noticed I cannot make my time step bigger than 0.1 and my array has to be small hence 50.
import math
import numpy as np
import matplotlib.pyplot as plt
alpha=3
beta=0.5
gamma=0.4
delta=3
tstep=0.05
t=np.zeros(50)
P=np.zeros(50)
N=np.zeros(50)
N[0]=2
P[0]=1
for i in range(0,49):
deltaN= (alpha * N[i] - beta * N[i] * P[i]) * tstep
deltaP= (gamma * N[i] * P[i] - delta * P[i]) * tstep
t[i+1]= t[i] + tstep
N[i+1]=N[i]+deltaN
P[i+1]=P[i]+deltaP
print t
print"N=", N
print"P=", P
plt.plot(t,N)
plt.plot(t,P)
My graph does not oscillate like the Lotka-Volterra model is supposed to. The line only oscillates once.