Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Scipy : ode module : issue enabling the step option of the solver

I wanted to store the different integration steps taken by the solver itself when I call it :

solver1.integrate(t_end)

So I did a while loop and enabled the step option setting its value to True:

while solver1.successful() and solver1.t < t0+dt:
    solver1.integrate(t_end,step=True)
    time.append(solver1.t)

Then I plot y, the result of integration and here comes my issue. I have instabilities which appear in a located area :

y enabling the step option of the solver

I thought it was because of the loop or something like that so I checked the result removing the step :

while solver1.successful() and solver1.t < t0+dt:
    solver1.integrate(t_end)

And surprise ... I have the correct result :

y disabling the step option of the solver

It's a quite weird situation ... I'd be grateful if someone of your guys could help me with this issue.

EDIT :

To set the solver I do :

solver1 = ode(y_dot,jac).set_integrator('vode',with_jacobian=True)
solver1.set_initial_value(x0,t0)

And I store the result using .append()

like image 290
kuider Avatar asked Mar 20 '13 13:03

kuider


People also ask

How to solve Ode problems in Python with SciPy?

Python ODE Solvers In scipy, there are several built-in functions for solving initial value problems. The most common one used is the scipy.integrate.solve_ivp function. The function construction are shown below:

How to solve system of ODEs using solve_IVP with lists?

We can solve this system of ODEs using solve_ivp with lists, as follows. We will try it first without specifying the relative and absolute error tolerances rtol and atol. # Define a function for the right side def dU_dx_new(x, U): """Right side of the differential equation to be solved.

How to solve the boundary value problem in SciPy?

In scipy, there are also a basic solver for solving the boundary value problems, that is the scipy.integrate.solve_bvp function. The function solves a first order system of ODEs subject to two-point boundary conditions.

Is it possible to have two Ode instances using zvode?

You cannot have two ode instances using the “zvode” integrator at the same time. This integrator accepts the same parameters in set_integrator as the “vode” solver. When using ZVODE for a stiff system, it should only be used for the case in which the function f is analytic, that is, when each f (i) is an analytic function of each y (j).


Video Answer


1 Answers

When you set step=True you are indirectly giving the vode._integrator.runner (a Fortran subroutine) an instruction to use itask=2, and the default is itask=1. You can get more details about this runner doing:

r._integrator.runner?

In SciPy 0.12.0 documentation you will not find an explanation about what is going on for the different itask=1 or itask=2, but you can find it here:

ITASK  = An index specifying the task to be performed.
!          Input only. ITASK has the following values and meanings.
!          1  means normal computation of output values of y(t) at
!             t = TOUT(by overshooting and interpolating).
!          2  means take one step only and return.
!          3  means stop at the first internal mesh point at or
!             beyond t = TOUT and return.
!          4  means normal computation of output values of y(t) at
!             t = TOUT but without overshooting t = TCRIT.
!             TCRIT must be input as RUSER(1). TCRIT may be equal to
!             or beyond TOUT, but not behind it in the direction of
!             integration. This option is useful if the problem
!             has a singularity at or beyond t = TCRIT.
!          5  means take one step, without passing TCRIT, and return.
!             TCRIT must be input as RUSER(1).
like image 138
Saullo G. P. Castro Avatar answered Sep 21 '22 04:09

Saullo G. P. Castro