In [2]:
    
from scipy.integrate import ode
birth_rate = 128
death_rate = 90
intraspecific_competition = 2
ps = [birth_rate, death_rate, intraspecific_competition]
def f(t, N, ps):
    return ps[0] * (N ** 2) / (N + 1) - ps[1] * N - ps[2] * (N ** 2)
def solve(N0, t0=0, t1=1, h=0.05):
    r = ode(f).set_integrator('dopri5')
    r.set_initial_value(N0, t0).set_f_params(ps)
    
    N = [N0]
    t = [t0]
    
    while r.successful() and r.t < t1:
        t.append(r.t + h)
        N.append(r.integrate(r.t + h))
    return N, t
    
In [3]:
    
num_part = ((ps[0] - ps[1] - ps[2]) ** 2 - 4*ps[1]*ps[2]) ** 0.5
L = (-num_part - ps[0] + ps[1] + ps[2]) / (-2 * ps[2])
K = (num_part - ps[0] + ps[1] + ps[2]) / (-2 * ps[2])
if K < L:
    L, K = K, L
print("Нижня межа: {}, верхня межа: {}".format(L, K))
    
    
In [16]:
    
L, K
    
    Out[16]:
In [4]:
    
options = [
    [1./4. * L, "< L/2"],
    [3./4. * L, "> L/2"],
    [L, "L"],
    [1./4. * (K + L), "< (K + L)/2"],
    [3./4. * (K + L), "> (K + L)/2"],
    [K, "K"],
    [1.25 * K, "> K"]
]
    
In [15]:
    
options
    
    Out[15]:
In [8]:
    
import matplotlib.pyplot as plt
t0 = 0
t1 = 0.5
fig, ax = plt.subplots()
lines=[]
for ind, opt in enumerate(options):
    N0 = opt[0]
    def_text = opt[1]
    N, t = solve(N0, h=0.01)
    lines.append(ax.plot(t, N, label=def_text)[0])
ax.legend(handles=lines)
plt.show()
    
    
In [6]:
    
options = [
    [100, "N(0) = 100"],
    [140, "N(0) = 140"],
    [180, "N(0) = 180"]
]
t1 = 24
def f(t, N):
    return -0.056 * N + 0.0004 * (N**2)
def solve(N0, t0=0, t1=1, h=0.05):
    r = ode(f).set_integrator('vode', method='bdf')
    r.set_initial_value(N0, t0)
    
    N = [N0]
    t = [t0]
    
    while r.successful() and r.t < t1:
        t.append(r.t + h)
        N.append(r.integrate(r.t + h))
    return N, t
    
In [7]:
    
plt.gcf().clear()
fig, ax = plt.subplots()
lines = []
for ind, opt in enumerate(options):
    N0 = opt[0]
    def_text = opt[1]
    N, t = solve(N0, t0=0, t1=t1, h=0.01)
    lines.append(ax.plot(t, N, label=def_text)[0])
    
ax.legend(handles=lines)
plt.show()
    
    Out[7]:
    Out[7]:
In [ ]: