# Pendulum

Author:
Thijs
History: Péndulo simple Theory : Pendulum (wikipedia) L-slider, θ0-slider, Calculate Period, Realistic timer and some other tricks. Scripting: #====================================== # Timer #====================================== SetActiveView[2] Lfact = {0.001, 1, 60} Time0 = GetTime[] Time = GetTime[] Seconds = Sum(Zip(f*(t-t0), f,Lfact, t,Time, t0,Time0)) Timer = Slider(0, 1, 0.001, 1, 180, false, true, false, false) #====================================== # Gravity, Length Pendulum, Initial Position and velocity #====================================== g = 9.80665 L = Slider(1, 2.5, 0.1, 1, 120, false, true, false, false) θ0= Slider(5°, 175°, 5°, 1, 120, true, true, false, false) ω0= 0 SetValue(L, 2) SetValue(θ0, 135°) #====================================== # Calculate Period, System of ODEs, Solve the system #====================================== Period'(x)=If(0≤x≤θ0, 4sqrt(L/(2g)) / sqrt(cos(x)-cos(θ0))) Period = NIntegral(Period', 0, θ0*0.999999999) θ'(t, θ, ω) = ω ω'(t, θ, ω) = -g / L sin(θ) Delete(f_1) f = NSolveODE({θ', ω'}, 0, {θ0, ω0}, Period) #====================================== # Plot the pendulum #====================================== SetActiveView[1] ca = CircularArc((0,0),(L;-θ0-90°),(L;θ0-90°)) ct = Mod(Seconds/Period, 1) θ = y(Point(f_1, ct)) Bob = L*(sin(θ),-cos(θ)) sL = Segment((0,0), Bob) #====================================== # Settings View 2 #====================================== SetActiveView[2] ShowAxes[false] ShowGrid[false] SetCoords(L , 20, 100) SetCoords(θ0, 20, 140) SetVisibleInView(Timer, 2, false) SetVisibleInView(Period', 2, false) SetVisibleInView(Period , 2, false) SetVisibleInView(f_1, 2, false) SetVisibleInView(f_2, 2, false) pix = x(Corner(2,3)-Corner(2,1))/x(Corner(2,5)) C4 = Corner(2,4) textPer = Text("Period = " Period , C4+pix*(20,-180), true) textSec = Text("Seconds= " Seconds, C4+pix*(20,-220), true) SetCoords(Start, 20, 250) SetVisibleInView(Start, 2, true) #====================================== # Settings View 1 #====================================== SetActiveView[1] CenterView[(0,0)] ShowGrid[1,false] ShowLabel(Bob, false) SetColor(Bob, "Red") SetPointSize(Bob, 9) ShowLabel(ca, false) SetLineStyle(ca,2) SetCaption(sL, "L") #====================================== # Start button: On Click #====================================== # SetValue(Timer,0) # SetValue[Time0,GetTime[]] # SetValue(Time,Time0) # StartAnimation(Timer,true) #====================================== # Timer: On Change #====================================== # SetValue[Time,GetTime[]]