Damped oscillation in a path. I saw this video, and in this minute, proposes the following equation:
$$
y + k_1 \;y'(x) + k_2 \;y''(x) = f(x) + k_3 f'(x)
$$
This is the equation that a "particle" would follow if attached with a spring to the curve $f(x)$ with one end in the curve and other end to the particle (or that's the way I think it works, no?). But how would you derive this equation intuitively? If you delete the right hand side of the equation is just a damped spring-mass system. Maybe this is a pretty stupid question, but how, from this equation you arrive to the new one, what is the line of reasoning?
 A: I think from the application side used in the video, you would rather start this as a mechanical particle with friction that is controlled by some input function $u$,
$$
y''+cy' = u.
$$
The most widely used "ad-hoc" control systems are PID controllers
$$
u=k_IE+k_Pe+k_De'
$$
where $E'=e$ and $e$ represents the distance to some desired state, in the most simple case $e=f-y$ (one could also use something like $e=r\tanh((f-y)/r)$ or other cut-off functions).
The video does not use the integration term, and introduces a parametrization for the coefficients that gives them a slightly more intuitive meaning, $k_p=\omega^2=(2\pi f)^2$, $c=2\omega\zeta$, ...
All-in-all this is done to motivate the discrete time dynamic that is actually used in the code. This is only loosely, esp. at large step sizes, related to the continuous dynamic of the DE. The important point is that the system has the same equilibrium, and that the quality of the convergence remains the same for about the same parameter ranges.
As the system is not conservative, using a semi-explicit Euler method just saves the introduction of a temporary variable for the old state, there are no order advantages. Thus any first-order changes on the right side are valid.

To avoid the numerical differentiation of the possible discontinuous desired position function $f$, one can introduce
$$
v=y'-k_De
$$
so that
\begin{align}
y'&=v+k_D(f-y)\\
v'&=y''-k_De'=-c(v+k_D(f-y))+k_P(f-y).
\end{align}

The expected dynamic of $y'=g-k_Dy$ is a stabilization of $y$ at $g/k_D$. If however the step size $T$ of the Euler step
$$
y[n+1]=y[n]+T(g[n]-k_Dy[n])
$$
is too large, it will overshoot increasing the distance from the equilibrium, and these overshoots accumulate exponentially. One simple trick to stabilize this is to avoid negative coefficients on the right side by changing $y[n]$ to $y[n+1]$, transferring this term to the left side
$$
y[n+1]=\frac{y[n]+Tk_Dg[n]}{1+Tk_D}.
$$
Now increasing $T$ just gives a value ever closer to $g[n]$.
For the full system this could look like (with some arbitrary switches between values at $n$ and $n+1$)
\begin{align}
y[n+1]&=\frac{y[n]+T(v[n]+k_Df[n]}{1+Tk_D}\\
v[n+1]&=\frac{v[n]+T(ck_D-k_P)(y[n+1]-f[n+1]))}{1+Tc}
\end{align}
