I have a simple pendulum oscillator program (written for me) with a dissipation term and a driving term. I use a simple solution (velocity verlet)for the ODE. It works quite well, but I'm unable to cause the driving term to only "act" intermittently, e.g. even tenth period (oscillation). Currently the driving term is constant and acts for a short time both sides of the zero crossing of bottom dead center in one direction.
Here's the ode: double A = - r*thetadot*abs(thetadot) +dr - ((4*pi*pi)/(period*period)) * sin(theta);
The drive (+dr) acts accordingly: if (theta > -0.03 && theta < +0.03 && thetadot <0.0 ) { dr = -d;} else {dr = 0;}
theta max. (the amplitude) is 0.1 (radian). r acts always, except, of course, when the acceleration (at the max. positions) is zero. A set of r and dr pairs will result in dynamic equilibrium.
So, My problem is to cause dr to act (fully) only every, desired, 30 seconds. i.e. fifteen periods if the period is two seconds. I thought I had it by detecting zero crossing [double crossed = theta * theta previous; thetaprevious is the position before the ODE solution begins.] and then stepping: if (crossed <= 0.0 ) { M++;}
then: if ( M % 30 == 0) {drive = 0; {else drive =1}
and added drive to the above: if (drive == 0 && theta > -0.03 && etc.
but it only drives the first half. I've given up and ask for help.