You are on page 1of 2

# #!

/usr/bin/env python3

## """Written by Oscar Serrano.

This program simulates the lotka volterra equations for a population of foxes and
rabbits.
"""

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

## def dP_dt(P, t):

"""Returns dC/dt.

P Requidered Population
P[0] Requidered Rabbits.
P[1] Requidered Foxes.
k Required Constants of growth.
"""
k = [1, 1, 1, 1]
dcdt = k[0] * P[0] - k[1] * P[0] * P[1]
dzdt = k[2] * P[0] * P[1] - k[3] * P[1]
return (dcdt, dzdt)

def main():
"""Main function."""
cont = True
test = 1
while cont:
C0 = float(input("Enter Initial Rabbits: "))
Z0 = float(input("Enter Initial Foxes: "))

P0 = (C0, Z0)
time = np.linspace(0, 24, 200)
P_t = odeint(dP_dt, P0, time)
Rabbits = P_t[:, 0]
Foxes = P_t[:, 1]
plt.plot(time, Rabbits, label="Rabbits")
plt.plot(time, Foxes, label="Foxes")
plt.xlabel("Time")
plt.ylabel("Population")
title = "Population vs Time " + "\nInitial Rabbits: " + str(C0) + " Initial
Foxes: " + str(Z0)
plt.title(title)
plt.legend()
path = "./" + str(test) + "_Pvtime.png"
plt.savefig(path)
plt.show()
plt.plot(Foxes, Rabbits)
plt.xlabel("Foxes")
plt.ylabel("Rabbits")
title = "Rabbits vs Foxes " + "\nInitial Rabbits: " + str(C0) + " Initial
Foxes: " + str(Z0)
plt.legend()
path = "./" + str(test) + "_RabbitsvsFoxes.png"
plt.savefig(path)
plt.show()
cont = input("Continue?\n")
if cont == "n" or cont == "N":
cont = False
else:
cont = True
test += 1

main()