Stiffness
Middle spring stiffness = 1.
dt = .01; //Make this smaller if you want better accuracy //Read the values into the parameters stiffness=document.inputs.stiff.value; //First give the variables some initial values x1=20; //initial positions of trolleys x2=0; vx1=0; //initial velocities vx2=0; running=true; StepModel(); //Start the simulation running
// Mass 2 is accelerated by forces in springs 2 and 3 vx2 += dt * (stiffness * (-x2) + 1*(x1-x2)); //Mass 1 is accelerated by forces in springs 1 and 2 vx1 += dt * (1 * (x2-x1) + stiffness*(- x1)); //Update the positions x1 += dt * vx1; x2 += dt * vx2; MoveTrolleys(x1,x2); if(running){setTimeout('StepModel()',10);}