以下可能是您想要的。您可以将中间值存储在列表中,然后再绘制该列表。那也需要存储x值。
import numpy as npimport matplotlib.pyplot as pltfrom scipy.integrate import odeintxs = []yd = []def dY(y, x): a = 0.001 yin = 1 C = 0.01 N = 1 dC = C/N b1 = 0 y_diff = -np.copy(y) y_diff[0] += yin y_diff[1:] += y[:-1] xs.append(x) yd.append(y_diff) return (a/dC)*y_diff+b1*dCx = np.linspace(0,20,1000)y0 = np.zeros(4)res = odeint(dY, y0, x)plt.plot(x,res, '-')plt.gca().set_prop_cycle(plt.rcParams['axes.prop_cycle'])plt.plot(np.array(xs),np.array(yd), '-.')plt.show()
虚线是相同颜色
y_diff的
res溶液的相应值。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)