我正在研究一组代码,我用它来解决一个普通的微分方程...我的代码正在工作,但是,我希望能够修改它来解决一组的微分方程不同的常数值。这就是我目前所拥有的,如果运行的话。
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
def f(w, x):
# d1 = omega lambda
d1 = w
b2 = 0.0
# 0.2<c<1.4, 0.20 increments
c = 0.2
q = (1 - d1 - (2*((d1**1.5)/c))) / (2 + (3*(b2)))
f = (d1**2) * (1 - d1) * ((1 / d1) + (2 / (c * (d1**0.5))) - ((3 * b2 * q) / (d1 * (1-d1))))
return f
#determine domain, x
x = np.linspace(-80, 80, 1000001)
d1 = 10 ** -8
sol = odeint(f, d1, x)
plt.xlabel("x")
plt.ylabel("Omega Lambda")
plt.plot(x, sol, 'r')
plt.show()
但是,我想构建一个图表,该图表由一组不同的c值产生的每一行组成...我希望生成的图表是:
c = 0.2,0.4,0.6,0.8,1.0,1.2,1.4
答案 0 :(得分:-1)
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
def f(w, x , b2 , c):
# d1 = omega lambda
d1 = w
# 0.2<c<1.4, 0.20 increments
#c = 0.2
q = (1 - d1 - (2*((d1**1.5)/c))) / (2 + (3*(b2)))
f = (d1**2) * (1 - d1) * ((1 / d1) + (2 / (c * (d1**0.5))) - ((3*b2*q)/(d1*1-d1))))
return f
#determine domain, x
x = np.linspace(-80, 80, 1000001)
d1 = 10 ** -8
b2 = 0.0
c = [ 0.2,0.4,0.6,0.8,1.0,1.2,1.4 ]
for i in c:
sol = odeint(f, d1, x, args = (b2 , i))
plt.xlabel("x")
plt.ylabel("Omega Lambda")
plt.plot(x, sol, 'r')
plt.show()