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