Omega
Stiffness
Damping
(this is a parameter, not the damping factor)
The black ball is the input.
The second trolley is connected to it by a spring.
The first trolley is also connected to ground through a damper.
dt = .01; //Make this smaller for better accuracy //Read the values into the parameters stiffness=document.inputs.stiff.value; damping=document.inputs.damp.value; omega=eval(document.inputs.omeg.value); theta=0; //First give the variables some initial values x1=0; //initial positions of trolleys x2=100; 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)/2; //Mass 1 is accelerated by forces in springs 1 and 2 and by damping vx1 += dt * (stiffness * (x2-x1 - x1) - damping*vx1); //Update the positions x1 += dt * vx1; x2 += dt * vx2; MoveTrolleys(x1,x2); if(running){setTimeout('StepModel()',10);}