-
Notifications
You must be signed in to change notification settings - Fork 31
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
18 changed files
with
69 additions
and
64 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
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
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,38 +1,38 @@ | ||
#!/usr/bin/python | ||
#!/usr/bin/python3 | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from scipy.integrate import odeint | ||
from math import * | ||
|
||
# Constants in model | ||
alpha=1.5 | ||
beta=0.5 | ||
gamma=0.4 | ||
delta=0.4 | ||
alpha1=1.2 | ||
beta1=0.4 | ||
alpha2=0.2 | ||
beta2=0.1 | ||
|
||
# Function that evaluates the RHS of the ODE. It has two components, | ||
# representing the changes in prey and predator populations. | ||
def deriv(x,t): | ||
return np.array([alpha*x[0]-beta*x[0]*x[1],-gamma*x[1]+delta*x[0]*x[1]]) | ||
def f(y,t): | ||
return np.array([alpha1*y[0]-beta1*y[0]*y[1], \ | ||
-alpha2*y[1]+beta2*y[0]*y[1]]) | ||
|
||
# Specify the range of time values where the ODE should be solved at | ||
time=np.linspace(0,70,500) | ||
|
||
# Initial conditions, set to the initial populations of prey and predators | ||
xinit=np.array([10,5]) | ||
yinit=np.array([10,5]) | ||
|
||
# Solve ODE using the "odeint" library in SciPy | ||
x=odeint(deriv,xinit,time) | ||
y=odeint(f,yinit,time) | ||
|
||
# Print the solutions | ||
for i in range(0,500): | ||
print((time[i],x[i,0],x[i,1])) | ||
#for i in range(0,500): | ||
# print(time[i],x[i,0],x[i,1]) | ||
|
||
# Plot the solutions | ||
plt.figure() | ||
p0,=plt.plot(time,x[:,0]) | ||
p1,=plt.plot(time,x[:,1]) | ||
plt.legend([p0,p1],["B(t)","C(t)"]) | ||
p0,=plt.plot(time,y[:,0]) | ||
p1,=plt.plot(time,y[:,1]) | ||
plt.legend([p0,p1],["Prey","Predators"]) | ||
plt.xlabel('t') | ||
plt.ylabel('Population') | ||
plt.show() |
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
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
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,4 +1,4 @@ | ||
#!/usr/bin/python | ||
#!/usr/bin/python3 | ||
from math import * | ||
|
||
# Function to consider | ||
|
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,4 +1,4 @@ | ||
#!/usr/bin/python | ||
#!/usr/bin/python3 | ||
import numpy as np | ||
from scipy.optimize import * | ||
|
||
|
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,4 +1,4 @@ | ||
#!/usr/bin/python | ||
#!/usr/bin/python3 | ||
import numpy as np | ||
import scipy.optimize as op | ||
|
||
|
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
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,4 +1,4 @@ | ||
#!/usr/bin/python | ||
#!/usr/bin/python3 | ||
from math import sqrt | ||
|
||
def f(x1,x2): | ||
|
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,4 +1,4 @@ | ||
#!/usr/bin/python | ||
#!/usr/bin/python3 | ||
from cvxopt import matrix,solvers | ||
|
||
# Constraints | ||
|
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,4 +1,4 @@ | ||
#!/usr/bin/python | ||
#!/usr/bin/python3 | ||
from scipy.optimize import linprog | ||
import numpy as np | ||
|
||
|
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,4 +1,4 @@ | ||
#!/usr/bin/python | ||
#!/usr/bin/python3 | ||
from math import * | ||
|
||
def f(x): | ||
|