Google Classroom
GeoGebraGeoGebra Classroom

A simple damped pendulum simulation

Script

#--------------------------------------------- # String #--------------------------------------------- L = Slider(1, 13, 0.01, 1, 150, false, true, false, false) SetValue(L, 11) posY = 430 SetCoords(L, 50, posY) SetVisibleInView(L, 1, false) O = (0, 0) SetVisibleInView(O, 1, false) #--------------------------------------------- # Slider to animate #--------------------------------------------- speed = 1 t = Slider(0, 1, 0.01, speed, 150, false, true, false, false) SetVisibleInView(t, 1, false) #--------------------------------------------- # Gravity #--------------------------------------------- g = Slider(0, 15, 0.01, 1, 150, false, true, false, false) SetCoords(g, 300, posY) SetValue(g, 9.81) SetVisibleInView(g, 1, false) #--------------------------------------------- # mass #--------------------------------------------- mass = Slider(0, 15, 0.01, 1, 150, false, true, false, false) SetValue(mass, 3) SetVisibleInView(mass, 1, false) #--------------------------------------------- # Slider for user to change the angle #--------------------------------------------- userAngle = Slider(0, 3.14, 0.01, 1, 150, false, true, false, false) SetValue(userAngle, pi * 0.6) SetCaption(userAngle, "θ") SetLabelMode(userAngle, 9) SetCoords(userAngle, 50, posY) #----------------------- # Initial conditions #----------------------- angleV = 0 angleA = 0 angle = pi * 0.6 damping = 0.791 #--------------------------------------------- # Force and position of Bob #--------------------------------------------- force = -g * sin(angle) fdamp = - damping * angleV posx = L * sin(angle); posy = -L * cos(angle); angleA = fdamp/mass + (force)/L #--------------------------- # Plot pendulum #--------------------------- s = Segment(O, (posx, posy)) SetLabelMode(s, 3) SetCaption(s, "L") SetLineThickness(s, 7) ShowLabel(s, true) c = Circle((posx, posy), 1) ShowLabel(c, false) SetFilling(c, 1) a = false SetValue(a, false) #--------------------------------------------- # Then add these lines in the slider 't' #--------------------------------------------- #SetValue(angleA, fdamp/mass + (force)/L) #SetValue(angleV, angleV + angleA/3) #SetValue(angle, angle + angleV/3) #--------------------------------------------------------- # Finally add these lines in the slider 'userAngle' #--------------------------------------------------------- #SetValue(angle, userAngle) #StartAnimation(t, false) #SetValue(a, false) #SetValue(angleV, 0) #SetValue(angleA, 0)