Skip to content
Advertisement

Python – Differential equation solver for time-dependent coefficients gives different dynamics for different time offsets

I am solving the dynamics of a system when it interacts with a pulse, which basically is solving a time-dependent differential equation. In general it works fine, but whenever I take the bandwidth of the pulse small, i.e. around unity, the solver depends on where the pulse starts t0. Let me give you the code and some pictures

JavaScript

and then just some expectation values and the plotting.

Proper dyanmics

Not good dynamics

As you can see from the pictures, the parameters are the same, the only difference is the time shift t0. It seems as whenever the pulse’s bandwidth is small, I have to start really close to t=0, which I don’t fully understand why. It should,’t be like that.

It is a problem of the solver? If so, what can I do to fix it? I’m now worried that this problem can manifest in other simulations I am running and I don’t realise.

Thanks, Joan.

Advertisement

Answer

This is a well-known behavior, there have been several questions on this topic.

In short, it is the step size controller. The assumption behind it is that the ODE function is smooth to a high order, and that local behavior informs the global behavior in a medium range. Thus if you start flat, with vanishing higher derivatives, the step size is quickly increased. If the situation is unfortunate, this will jump over the non-smooth bump in all stages of the integrator step.

There are two strategies to avoid that

  • set max_step to 2*tau so that the bump is surely encountered, the step size selection will make sure that the sampling is dense around the jumps.

  • use separate integration for the pieces of the jump, so that the control input inside each segment is a constant.

enter image description here

The first variant is in a small way an abuse of the step size controller, as it works outside specifications in some heuristic emergency mode around the jumps. The second variant requires a little more coding effort, but will have less internal steps, as the ODE function for each segment is again completely smooth.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement