-1

我正在尝试修改 scipy 食谱中的代码

scipy 食谱解决了一些状态方程,然后打印它们:

wsol = odeint(two_springs.vectorfield, w0, t, args=(p,),
              atol=abserr, rtol=relerr)

for t1, w1 in zip(t, wsol):
    print t1, w1[0], w1[1], w1[2], w1[3]

scipy 食谱要求您运行程序并将打印的内容保存到文件中:

程序.py > 文件.dat

然后一个单独的绘图功能要求您从该文件加载数据

t, x1, xy, x2, y2 = loadtxt('two_springs.dat', unpack=True)

在绘图之前

plot(t, x1, 'b', linewidth=lw)
plot(t, x2, 'g', linewidth=lw)

我只想设置 t,x1,x2 和 plot

谁能告诉我该怎么做?

这就是我要修改的内容:

http://wiki.scipy.org/Cookbook/CoupledSpringMassSystem

4

1 回答 1

0

我假设那wsol是 Nx4 ndarray,因此您只需要解包这些值:

x1, xy, x2, y2 = wsol.T
于 2013-08-14T00:53:12.870 回答