Omega
Stiffness
Damping
(this is a parameter, not the damping factor)
Note how the oscillation builds up to a limit - unless the damping is zero
even when the vibration is not quite at the resonant frequency.
If the vibration is far from the resonant frequence you can see 'beats;
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 trolley vx1=0; //initial velocity running=true; StepModel(); //Start the simulation running
theta+=omega*dt; excitation=Math.sin(theta)*5; exrate=omega*Math.cos(theta)*5; //Mass 1 is accelerated by force in spring 1 and by damping vx1 += dt * (stiffness * (excitation-x1) + damping * (exrate-vx1)); //Update the position x1 += dt * vx1; MoveTrolleys(x1,x2); if(running){setTimeout('StepModel()',10);}