Skip to content Skip to sidebar Skip to footer

Scipy Odeint - Different Values Of Arguments In Each Timestep Tx

I am trying to simulate some dynamic models using SciPy. I have model definition: def model(y, t, control_signal): dy/dt = some_function_of_time_and_y return dy I defined

Solution 1:

In scipy.interpolate.interp1d you can define the interpolation mode as "zero-hold" or order 0 spline, that is, piecewise constant, with `kind="zero". Use that to define the time dependency of your control.

contfunc = interp1d(t_list,control, kind="zero");

def model(y, t, control_signal):
    u = contfunc(t);
    dydt = some_function_of_time_and_y_and_u
    return dydt

The dimension error might be a different issue. To debug that, either use a debugger if available or add print statements for the size/shape of inputs and outputs. State and derivative should be flat arrays of the same size.

Do not forget to set the maximal time step to smaller than the step size of the control, it should not matter but could be a source for strange errors.


Post a Comment for "Scipy Odeint - Different Values Of Arguments In Each Timestep Tx"