In [1]:
from sympy import *
import matplotlib.pyplot as plt
import numpy as np
init_printing()
In [2]:
p = Function('p')
t, t0, tau, p0, a, b = symbols('t t_0 tau p_0 alpha beta', real=True, positive=True)
dgl = Eq(p(t).diff(t), (a - b*p(t)) * p(t))
dgl
Out[2]:
$\displaystyle \frac{d}{d t} p{\left(t \right)} = \left(\alpha - \beta p{\left(t \right)}\right) p{\left(t \right)}$
In [3]:
sol = dsolve(dgl, p(t))
sol
Out[3]:
$\displaystyle p{\left(t \right)} = \frac{\alpha}{\beta \left(1 - e^{\alpha \left(C_{1} - t\right)}\right)}$
In [4]:
aw = {p(t0): p0}
sol_aw = dsolve(dgl, p(t), ics=aw)
sol_aw
Out[4]:
$\displaystyle p{\left(t \right)} = \frac{\alpha}{\beta \left(1 - e^{\alpha \left(- t + t_{0} + \frac{\log{\left(- \frac{\alpha}{\beta p_{0}} + 1 \right)}}{\alpha}\right)}\right)}$
In [5]:
fig, ax = plt.subplots()
tn = np.linspace(0, 5, 101)
p_ = sol_aw.rhs.subs({a:1, b:1, t0:0, p0:.1}) # Anfangsbedingung y(0)= 0.1
pn = lambdify(t, p_)
ax.plot(tn, pn(tn));
No description has been provided for this image
In [6]:
sol_aw.rhs.subs({a:1, b:1, t0:0, p0:.1})
Out[6]:
$\displaystyle \frac{1}{1 + 9.0 e^{- t}}$
In [8]:
fig = plt.figure(2)
ax = fig.gca()
tn = np.linspace(0, 5, 201)
for p0_ in [.1, .5, .75, 1.00001, 1.25]: # mehrere Anfangsbedingungen
    p_ = sol_aw.rhs.subs({a:1, b:1, t0:0, p0:p0_})
    pn = lambdify(t, p_)
    ax.plot(tn, pn(tn), label=f"zu p(0)= {p0_}")
ax.legend()
ax.set_title(f"Lösungen von ${latex(dgl.subs({a:1, b:1, t0:0, p0:p0_}))}$");
No description has been provided for this image
In [ ]:
 
In [ ]: