簡體   English   中英

使用dopri5方法進行Scipy ODE集成

[英]Scipy ODE integration using dopri5 method

在求解耦合微分方程時,我遇到了錯誤,但由於我是python的新手,所以我沒有得到它。

“ dopri5:步長變得太小self.messages.get(idid,'意外的idid =%s'%idid))

“請有人幫助我提供關於ode積分器的正確解釋。

  # zombie apocalypse modeling import numpy as np import matplotlib.pyplot as plt plt.ion() from scipy.integrate import ode G=6.67384*10**(-11) K=5380.3 v=5/3 r0=1 density0=5*10**(7) Pressure0=K*density0**(v) mass0=(4/3)*np.pi*density0*r0**(3) c=299792458 y_0=[mass0,Pressure0] def f(r,y): mass1=4*np.pi*(y[1]/K)**(1/v) Pressure1=G*( ((y[1]/K)**(1/v)) + (y[1]/(c**2)) )*( (y[0])+(4*np.pi*(r**3)*y[1]/(c**2)) )/( 1-G*y[0]/(r*c**2) ) #phi1=( G*y[0] + (4*np.pi*G*r**(3)*P/(c**2)) )/( (r*c**2)*( r-2*G*m/(c**2) ) return([mass1,Pressure1])#,phi1) def my_odeint(f, y0, t): ''' ODE integrator compatible with odeint, that uses ode underneath ''' y0 = np.asarray(y0) backend = "dopri5" #backend = "dop853" solver = ode(f) solver.set_integrator(backend) # nsteps=1 t0 = t[0] t_final = t[-1] solver.set_initial_value(y0, t0) y_result = [y0] i = 1 current_t = t[i] z=y0 while solver.successful() and solver.t < t_final and z[1]>0: solver.integrate(current_t, step=1) i += 1 z=solver.y if i<len(t) : current_t = t[i] print(i) y_result.append(solver.y) return np.array(y_result) t_1=np.linspace(10,10**5,10**5) print(len(t_1)) cal=my_odeint(f,y_0,t_1) 

我不知道如何解決這個問題,尤其是因為scipy沒有隱式方法...

dopri5或也稱為rk45是一種Runge-Kutta方法,將4階和5階混合。 5階方法用作精確值的代理,以估計4階方法的誤差。 如果誤差沒有落在相對於步長和問題規模的預定范圍內,則減小或增加步長。 這允許以最小的努力使積分具有一些預定的全局誤差。

在僵硬的系統中,可能會發生步長減小無法成功將錯誤推回到允許范圍內的情況。 可能涉及一些故障保護措施,以便在集成間隔的明顯時間內發現此不良行為,從而使所有錯誤估計均無效。

剛性系統集成的解決方案是使用隱式方法,例如並置方法。 我沒發現它們有任何暗示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM