我目前正在编写一组代码,用来解决一个常微分方程……我的代码是工作的,但是,我希望能够修改它,以解决一组不同常量的微分方程。这就是我目前所拥有的,如果ran可以工作的话。
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的图表是:
c = 0.2,0.4,0.6,0.8,1.0,1.2,1.4
发布于 2017-11-06 13:00:21
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()
https://stackoverflow.com/questions/41861859
复制相似问题