我正在嘗試使用scipy的ode求解器來(lái)繪制2D方程組之間的相互作用。我正在嘗試通過(guò)以下代碼塊更改傳遞給求解器的參數(shù):# define maximum number of iteration steps for ode solver iterationm = 1 #power of iterationN = 2**m #number of steps# setup a try-catch formulation to increase the number of steps as needed for solution to convergewhile True: try: z = ode(stateEq).set_integrator("vode",nsteps=N,method='bdf',max_step=5e5) z.set_initial_value(x0, t0) for i in range(1, t.size): if i%1e3 == 0: print 'still integrating...' x[i, :] = z.integrate(t[i]) # get one more value, add it to the array if not z.successful(): raise RuntimeError("Could not integrate") break except: m += 1 N = 2**m if m%2 == 0: print 'increasing nsteps...' print 'nsteps = ', N運(yùn)行它不會(huì)中斷while循環(huán)。它會(huì)永遠(yuǎn)增加nstep,而系統(tǒng)永遠(yuǎn)也不會(huì)解決。我認(rèn)為,如果不將其放入while循環(huán)中,則系統(tǒng)會(huì)得到解決,因?yàn)榻鉀Q方案已被標(biāo)繪。while循環(huán)是否必要?我的求解器公式不正確嗎?
Python SciPy ODE求解器未收斂
桃花長(zhǎng)相依
2021-05-06 14:16:06