Running ode, dopri5 method, error: unsupported operand type 'ode'

110 views Asked by At

I'm a beginning programmer and I would like to integrate a function using ode 'dopri5', but I don't think I'm doing it correctly. The reference wasn't much help and I'm having an error that I don't recognize. So, originally I was using odeint, and it was working fine. Here is that chunk of code:

Itmp = odeint(te.rhs, Itmp, [xLim[i], xLim[i+1]], mxstep=10000,
                          atol=1e-11, rtol=1e-11, args=(f,))[1]

And my attempt to integrate using dopri5 is this:

Itmp = ode(te.rhs).set_integrator('dopri5', max_step=10000,atol=1e-11, rtol=1e-11)

The error I get is saying that Itmp is type 'ode' while I need it to be a float, like the odeint gives me.

Here is the specific error, (I try to subtract Itmp from a float):

unsupported operand type(s) for -: 'ode' and 'float'

And when I use the python debugger and try to print out Itmp, it gives me

<scipy.integrate._ode.ode object at 0x10d6ab410>

And after I continue it stops with the above error. I'm guessing I don't have the ode command written out correctly. Any help would be greatly appreciated!

1

There are 1 answers

0
Lutz Lehmann On

The return value of the constructor of the ode class is an instance object of type ode. At this point, no integration has taken place. For that you need to call the step functions of the integrator. After the step, the new state is in the y field of the ode object.

Consult the documentation of the ode class for further details.

You should have noted that you did not pass neither the initial conditions nor the end of the integration interval to the integrator.