4

I am working on translating a model from MATLAB to Python. The crux of the model lies in MATLAB's ode15s. In the MATLAB execution, the ode15s has standard options:

options = odeset()
[t P] = ode15s(@MODELfun, tspan, y0, options, params)

For reference, y0 is a vector (of size 98) as is MODELfun.

My Python attempt at an equivalent is as follows:

ode15s = scipy.integrate.ode(Model.fun)
ode15s.set_integrator('vode', method = 'bdf', order = 15)
ode15s.set_initial_value(y0).set_f_params(params)
dt = 1 
while ode15s.successful() and ode15s.t < duration:
     ode15s.integrate(ode15s.t+dt)

This though, does not seem to be working. Any suggestions, or an alternative?

Edit: After looking at the output, the result I'm getting from the Python is either no change in some elements of y0 over time, or a constant change at each step for the rest of the y0. Any experience with something like this?

user3780330
  • 71
  • 1
  • 5
  • "... does not seem to be working." What does that mean? Do you get an error? An unexpected result? Please clarify. – Warren Weckesser Jun 26 '14 at 18:04
  • 1
    Are you sure you have correctly translated the Matlab code in `MODELfun` to Python? (Double-check the code, and also verify by picking some random time and parameter values, and checking that the functions `MODELfun` and `Model.fun` give the same result.) – Warren Weckesser Jun 26 '14 at 18:21

2 Answers2

2

According to the SciPy wiki for Matlab Users, the right way for using the ode15s is

scipy.integrate.ode(f).set_integrator('vode', method='bdf', order=15)
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
  • 2
    The method part is reasonable; the `order` parameter doesn't make any sense. VODE doesn't implement a BDF method of order greater than 5; for BDF methods of order greater than 6, the method isn't zero-stable, so the numerical solution wouldn't be stable with respect to perturbations in the initial conditions. Omitting the `order` parameter is probably fine, because `ode15s` uses a similar family of methods (either NDF or BDF). – Geoff Oxberry Oct 17 '14 at 18:47
  • The Wiki link is out of date – Graham G Aug 23 '20 at 17:43
1

One point to make clear is that, unlike Matlab's ode15s, the scipy integrator 'vode' does not support models with a mass matrix. So any recommendation should include this caveat.

Graham G
  • 551
  • 5
  • 14