Ich beschäschäftige mich gerade mit der numerischen Lösung von DGL. Für Python hab ich dazu die odeint-Funktion gefunden.
Ich bekomme meine DGL aus der vorangegangen Rechnung als Vektor übergeben. Sprich jede Zeile ist quasi eine der DGL, welche zum Teil gekoppelt sind.
Der Code zur berechnung sieht dann quasi so aus:
Code: Alles auswählen
#geht
import matplotlib.pyplot as plt
import scipy.integrate as sci
import numpy as np
def con(c, t):
a=0
cbdt = np.matrix([[-b_1 * c[1]], [b_1 * c[1] - b_2 * c[2]], [b_2 * c[2]]])
return(a, cbdt[0], cbdt[1], cbdt[2])
b_1 = .5
b_2 = .1
c0 = [0, 1, 0, 0]
t = np.linspace(0 , 10, 1000)
sol = sci.odeint(con, c0 , t)
plt.plot(t, sol[:,1], 'r-' )
plt.plot(t, sol[:,2], 'g-' )
plt.plot(t, sol[:,3], 'b-')
plt.show()
Code: Alles auswählen
#geht nicht
import matplotlib.pyplot as plt
import scipy.integrate as sci
import numpy as np
def con(c, t):
cbdt = np.matrix([[-b_1 * c[1]], [b_1 * c[1] - b_2 * c[2]], [b_2 * c[2]]])
return(cbdt[0], cbdt[1], cbdt[2])
b_1 = .5
b_2 = .1
c0 = [1, 0, 0]
t = np.linspace(0 , 10, 1000)
sol = sci.odeint(con, c0 , t)
plt.plot(t, sol[:,1], 'r-' )
plt.plot(t, sol[:,2], 'g-' )
plt.plot(t, sol[:,3], 'b-')
plt.show()
Wenn mir jemand das Phänomen erklären könnte und vll auch eine korrekte Lösung dafür anbietet wäre ich sehr dankbar.
Mit freundlichen Grüßen
Pumpkinpy