Diferenciální rovnice pro začátečníky#
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from scipy.integrate import solve_ivp
pocatecni_podminka = [0.1]
meze = [0,10]
def rovnice(t, x, h=0):
r = 1
K = 1
return r*x*(1-x/K) - h
t=np.linspace(*meze, 100) # graf reseni
reseni = solve_ivp(
rovnice,
meze,
pocatecni_podminka,
t_eval=t, ## zde je možné zadat pole hodnot, kde se mají určit řešení
)
reseni
message: The solver successfully reached the end of the integration interval.
success: True
status: 0
t: [ 0.000e+00 1.010e-01 ... 9.899e+00 1.000e+01]
y: [[ 1.000e-01 1.095e-01 ... 9.995e-01 9.995e-01]]
sol: None
t_events: None
y_events: None
nfev: 62
njev: 0
nlu: 0
fig,ax = plt.subplots(1)
ax.plot(t,reseni.y.T)
[<matplotlib.lines.Line2D at 0x7f9e9598fbc0>]
ax.set(
ylim = (0,None),
title = "Řešení diferenciální rovnice",
xlabel=r"$t$",
ylabel=r"$x$",
)
fig
df = pd.DataFrame(reseni.y.T, index=t)
df
0 | |
---|---|
0.00000 | 0.100000 |
0.10101 | 0.109465 |
0.20202 | 0.119702 |
0.30303 | 0.130753 |
0.40404 | 0.142664 |
... | ... |
9.59596 | 0.999297 |
9.69697 | 0.999345 |
9.79798 | 0.999398 |
9.89899 | 0.999455 |
10.00000 | 0.999507 |
100 rows × 1 columns