PresetTimeCallback with array in affect function

I’m trying to understand how to use the PresetTimeCallback(tstops,affect!) where tstops is an array of time steps and the affect function should also affect the integration each time with different values.
For example, for one time and one affect I used:

DE.PresetTimeCallback(t1, integrator -> integrator.p[1] += v1)

This works.
For a list of timesteps

DE.PresetTimeCallback([t1, t2, t3], integrator -> integrator.p[1] += v1);

works as well. It just applies the same v1.
However, I would like it to apply at each different time t1, t2, t3, … the values v1, v2, v3… I tried something sort of…

DE.PresetTimeCallback([t1, t2, t3], integrator -> integrator.p[1] += [v1, v2, v3]);

but that doesn’t work.
Any suggestion how to do that?

Have your affect function increment a counter each time it is called and use that to index into the vector of v values. This would probably work well as a function-like object (to avoid global variables).

1 Like