forked from ricardo2911/demo-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
61 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
""" | ||
Module containing matlab code for visualization of the Lotka Volterra model. | ||
Adapted from: | ||
https://github.com/scipy/scipy-cookbook/blob/master/ipython/LotkaVolterraTutorial.ipynb | ||
""" | ||
|
||
import matplotlib.pyplot as plt | ||
import os | ||
|
||
|
||
def _createfolder(folder="graphs"): | ||
""" Make directory named folder in current working directory, | ||
if it doesn't exist. Returns name of folder. | ||
""" | ||
if not os.path.isdir(folder): | ||
os.mkdir(folder) | ||
|
||
return folder | ||
|
||
|
||
def evolution(t, X, savefig=True, showfig=True): | ||
""" Simple function to plot temporal evolution of X. """ | ||
rabbits, foxes = X.T | ||
|
||
fig1 = plt.figure() | ||
plt.plot(t, rabbits, "r-", label="Rabbits") | ||
plt.plot(t, foxes, "b-", label="Foxes") | ||
|
||
plt.grid() | ||
plt.legend(loc="best") | ||
plt.xlabel("time") | ||
plt.ylabel("population") | ||
plt.title("Evolution of fox and rabbit populations") | ||
|
||
if savefig: | ||
foldername = _createfolder() | ||
fig1.savefig(os.path.join(foldername, "rabbits_and_foxes_1.png")) | ||
|
||
if showfig: | ||
fig1.show() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
# Code adapted from https://scipy-cookbook.readthedocs.io/items/LoktaVolterraTutorial.html | ||
# Code adapted from https://github.com/scipy/scipy-cookbook/blob/master/ipython/LotkaVolterraTutorial.ipynb | ||
|
||
import numpy as np | ||
from scipy import integrate | ||
from LotkaVolterraModel import dX_dt, check_equilibrium | ||
|
||
from Visualization import evolution | ||
|
||
# Definition of parameters | ||
a = 1.0 # natural growth rate of rabbits (prey) | ||
b = 0.1 # natural dying rate of rabbits | ||
c = 1.5 # natural dying rate of foxes | ||
a = 1.0 # natural growth rate of rabbits (prey) | ||
b = 0.1 # natural dying rate of rabbits | ||
c = 1.5 # natural dying rate of foxes | ||
d = 0.75 # factor describing growth of foxes based on caught rabbits | ||
|
||
""" | ||
# Running dynamical system: | ||
t = np.linspace(0, 15, 1000) # time | ||
X0 = np.array([10, 5]) # initial conditions: 10 rabbits and 5 foxes | ||
X, infodict = integrate.odeint(lambda x, _: dX_dt(x, a, b, c, d), X0, t, full_output=True) | ||
""" | ||
X, infodict = integrate.odeint( | ||
lambda x, _: dX_dt(x, a, b, c, d), X0, t, full_output=True | ||
) | ||
|
||
evolution(t, X) | ||
|
||
|
||
print("Checking fix points of ODE.") | ||
check_equilibrium(a, b, c, d) | ||
# print("Checking fix points of ODE.") | ||
# check_equilibrium(a, b, c, d) |