Python SciPy ODE求解器未收敛

我正在尝试使用scipy的ode求解器来绘制2D方程组之间的相互作用。我正在尝试通过以下代码块更改传递给求解器的参数:


# define maximum number of iteration steps for ode solver iteration

m = 1 #power of iteration

N = 2**m #number of steps


# setup a try-catch formulation to increase the number of steps as needed for solution to converge

while 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

运行它不会中断while循环。它会永远增加nstep,而系统永远也不会解决。我认为,如果不将其放入while循环中,则系统会得到解决,因为解决方案已被标绘。while循环是否必要?我的求解器公式不正确吗?


桃花长相依
浏览 281回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python