SHM of a horizontal 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 simple harmonic motion (SHM) in [b]real time[/b], ignoring friction, of a horizontal spring. The animation [b]uses the minimum of formulas[/b] (no trigonometry or differential calculus), only making the necessary changes in the vectors that govern the movement.[br][br]A mass [i]m[/i], represented by the blue point [color=#0000ff]M[/color], is at the end of a spring with a constant elasticity [i]k[/i]. You can choose both constants within a range in the left panel.[br][br]At the start, the construction shows the blue point [color=#0000ff]M[/color] at rest: the spring exerts no force on it. [b]Drag [/b][color=#0000ff]M[/color] to the right to stretch the spring. The distance you drag it will determine the [i]amplitude[/i]. Notice that as you drag [color=#0000ff]M[/color], [b][color=#cc0000]the theoretical period does not change, as it does not depend on the amplitude[/color][/b]. The reason is that with a greater amplitude, the [i]restoring force[/i] of the spring will be stronger, so in the end [color=#0000ff]M[/color] will complete each oscillation in the same amount of time (we will demonstrate this [b][color=#cc0000][i]isochronism [/i][/color][/b]in the next activity).[br][br]This separation from the rest position will cause the spring to resist, producing an acceleration [b][color=#6aa84f]a[/color][/b] (in green) whose direction is always towards the rest position. This acceleration is not constant, but at each position of [color=#0000ff]M[/color], it is proportional to the distance [i]x[/i] from [color=#0000ff]M[/color] to the rest point ([i]Hooke's law[/i]).[br][br]Press the button [img]https://www.geogebra.org/resource/yxbcmb2f/CZJZaLQBirTUHVXU/material-yxbcmb2f.png[/img] to activate the animation. The acceleration [b][color=#6aa84f]a[/color][/b] causes [color=#0000ff]M[/color] to acquire a variable velocity [color=#cc0000][b]v[/b][/color] (in red). Its magnitude is proportional to the elasticity [i]k[/i] and the distance [i]x[/i], and inversely proportional to the mass [i]m[/i]. That is, |[b][b][color=#6aa84f]a[/color][/b][/b]| [b]= [/b][i]k[/i]/[i]m[/i] x.[br][list][*][color=#999999]We know that the spring’s force is, on one hand, equal to the mass times acceleration[color=#999999]: [i]m[/i][b] [/b]|[b][b][color=#6aa84f]a[/color][/b][/b]|, and on the other hand, proportional to the distance [i]x[/i] traveled: [i]k[/i][b] [/b][i]x[/i]. From this, we deduce that [color=#999999]|[/color][b][color=#999999][b][b][color=#6aa84f]a[/color][/b][/b][/color][/b][color=#999999]|[/color] [b]= [/b][i]k/m[/i][b] [/b][i]x[/i]. [/color][/color][/*][/list]So we adapt the slider [b]anima[/b]’s script to this situation:[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]That is, every time a very small amount of time [i]dt[/i] passes, by definition of acceleration, the velocity [color=#cc0000][b]v[/b][/color] increases by [i]dt[/i] [b][b][color=#6aa84f]a[/color][/b][/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 (we use an auxiliary vector to retain the value of vt before updating the value of v)[/color][br][color=#0000ff]SetValue(aux, v)[br][color=#0000ff]SetValue[/color](v, v + dt a)[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=#0000ff][color=#0000ff]SetValue[/color](reg, If(x(aux) > 0 ∧ x(v) < 0, Append(t, reg), reg))[br][color=#0000ff]SetValue[/color](osci, If(x(aux) > 0 ∧ x(v) < 0, osci + 1, osci))[br][br][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 horizontal spring