SHM of a vertical spring

[color=#0000ff][i][color=#0000ff][i][color=#999999]This activity belongs to the GeoGebra book [url=https://www.geogebra.org/m/mes4bgft]The Domain of the Time[/url].[/color][/i][/color][/i][/color][br][br]This animation simulates a simple harmonic motion (SHM) in [b]real time[/b], neglecting friction, for a vertical spring. The animation [b]uses minimal formulas[/b] (no trigonometry or differential calculus), only making the necessary changes to the vectors guiding the motion.[br][br]This motion is nearly identical to that of the previously seen horizontal spring SHM, except for the change in orientation. The only difference between them is that now, in vertical oscillation, gravity is involved, shifting the center of the oscillation from the spring's [i]rest position[/i] to the [i]equilibrium position[/i] between the restoring force of the spring and gravity.[br][br]At the start, the construction shows the blue point [color=#0000ff]M[/color] in equilibrium: the spring exerts the same force on it, but in the opposite direction of gravity. [b]Drag [/b][color=#0000ff]M[/color] down to stretch the spring. The distance you drag it will determine the [i]amplitude[/i].[br][br]This displacement from the equilibrium position causes the spring to resist, creating an acceleration [b][color=#6aa84f]a[/color][/b] (in green), which always points toward the equilibrium point. Press the button [img]https://www.geogebra.org/resource/yxbcmb2f/CZJZaLQBirTUHVXU/material-yxbcmb2f.png[/img] to activate the animation.[br][br]To adapt the slider script, we simply replace:[br][br] SetValue([color=#cc0000][b]v[/b][/color], [color=#cc0000][b]v[/b][/color] + [i]dt[/i] [b][color=#6aa84f]a[/color][/b])[br][br]with:[br][br] SetValue([color=#cc0000][b]v[/b][/color], [color=#cc0000][b]v[/b][/color] + [i]dt[/i] ([b][color=#6aa84f]a[/color][/b] + [b][color=#6aa84f]g[/color][/b]))
[b]SCRIPT FOR SLIDER anima[/b][br][br][color=#cc0000][color=#cc0000]# Calculate the elapsed seconds dt; add one second if t1(1) < tt[/color][/color][br][color=#999999]SetValue(tt, t1(1))[br]SetValue(t1, First(GetTime(), 3))[br]SetValue(dt, (t1(1) < tt) + (t1(1) − tt)/1000)[/color][br][br][color=#cc0000]# Move M [/color][br][color=#999999][color=#999999]SetValue[/color](aux, v)[/color][br][color=#0000ff]SetValue(v, v + dt (a + g))[br][/color][color=#999999][color=#999999]SetValue[/color](M, M + dt v)[/color][br][br][color=#cc0000]# Record the period time and the number of complete oscillations[/color][br][color=#999999][color=#999999]SetValue[/color](reg, If(y(aux) < 0 ∧ y(v) > 0, Append(t, reg), reg))[br][color=#999999]SetValue[/color](osci, If(y(aux) < 0 ∧ y(v) > 0, osci + 1, osci))[/color][color=#0000ff][br][br][br][br][color=#999999][color=#999999][color=#0000ff][color=#0000ff][color=#999999][color=#999999]Author of the activity and GeoGebra construction: [/color][/color][/color][color=#0000ff][color=#999999][color=#999999][url=https://www.geogebra.org/u/rafael]Rafael Losada[/url].[/color][/color][/color][/color][/color][/color][/color]

Information: SHM of a vertical spring