2016-10-05 13 views
0

scipyバージョン0.18.0を使用し、現時点では 私の頭を実際に傷つける。 私は、次の最低限の例にコードを削減:Scipy odeソルバー

は、オブジェクトは、それが成功した私に語ったが、戻り値 は、長さ1のnumpyの配列である最も簡単な微分方程式可能

def phase(t, y): 
    c1 = y 
    dydt = - c1 
    return dydt 

c1 = 1.0 
y0 = c1 
t = np.linspace(0,1,100) 
ode_obj = sp.integrate.ode(phase) 
ode_obj.set_initial_value(y0) 
sol = ode_obj.integrate(t) 

を解決しよう

文書は極端に疎であり、間違って使用している場合は とは分かりません。

助けを借りてくれてありがとう。

ご挨拶。

答えて

0

はgithubのhttps://github.com/scipy/scipy/issues/1976 にこの問題を発見、これはこの方法で行われている理由、それは 明確になる(最終点の方向に段階的に)これは基本的にそれがどのように動作するかを説明し、あなたがこれらの初期 値ソルバーがどのように機能するかを考えるとき。上記の私のコードは 次のようになります。

import scipy as sp 
import pylab as pb 

def phase(t, y): 
    c1 = y 
    dydt = - c1 
    return dydt 

c1 = 1.0 
t0 = 0.0 # not necessary here 
y0 = c1 
t1 = 5.0 

t = [] 
sol = [] 
ode_obj = sp.integrate.ode(phase) 
ode_obj.set_initial_value(y0, t=t0) 
ode_obj.set_integrator('vode',method='bdf',rtol=1.e-12) 
sol = ode_obj.integrate(t) 
while ode_obj.successful() and ode_obj.t < t1: 
    ode_obj.integrate(t1,step=100) 
    t.append(ode_obj.t) 
    sol.append(ode_obj.y) 

pb.plot(t,sol) 
pb.show() 

これは以下の出力を生成します: enter image description here