Matlab 相当于 scipy 的 'vode' 和 'zvode' ode 例程

计算科学 matlab Python
2021-12-08 21:57:04

在 python 中,我使用了ode来自scipy.integrate. 在那里,我使用vode积分器和zvode积分器来解决一些数字颂歌。我对这些方法提供的解决方案很满意,现在想知道 matlab 中的等效方法是什么。

我不熟悉 odes 的复杂性(刚度以及在每种情况下都适合哪些求解器)我只是想知道是否有与上述两种积分器方法等效的 matlab 例程,我可以轻松使用。

这是我如何定义一个应该及时前进的函数的示例

def time_march2(y0, x1_max):

   y0 = np.asarray(y0)
   t0 = 0
   tlimit = 100.0 

   backend = 'vode'  
   solver = ode(f2).set_integrator(backend, nsteps=1)
   solver.set_initial_value(y0, t0)
   # suppress Fortran-printed warning
   solver._integrator.iwork[2] = -1

   solution_y = [y0]
   solution_t = [t0]
   warnings.filterwarnings("ignore", category=UserWarning)

   while solver.successful() and solver.y[0] < x1_max and solver.t < tlimit:
      solver.integrate(tlimit, step=True)          
      solution_y.append(solver.y)
      solution_t.append(solver.t)


   warnings.resetwarnings()
   solution_y = np.array(solution_y)
   solution_t = np.array(solution_t)


   return solution_t, solution_y
1个回答

如果您想使用基本的 MATLAB 例程,ode15s是最接近的模拟程序(请参阅Shampine 的论文),尽管您必须设置选项以确保它使用 BDF 方法而不是默认的 NDF 方法。

如果你只想要一个 MATLAB 接口,SUNDIALS有一个 CVODE 的 MATLAB 接口;CVODE 是 VODE 的更新版本。