Thanks for the reply.
Apologies, I wasn't very clear. I have posted a version of the for loop below. All variables are initialised and initial conditions specified. I'm not sure why it's not working, I have decided to use the past values of x2 and xc to determine cpto for the current loop. The...
I am editing code which was developed to model a mass spring damper system in the time domain using the equations of motion of the system. One damping ratio in particular,cpto, was constant originally but I am trying to vary it according to the if statement below.
if k3*(x2(i)-x1(i))>=0 &&...