There is a pendulum with a motor mounted at its point of rotation. The motor can generate a rotational force at any time, thus changing the dynamics to $θ" = −a*sinθ − b*θ" + u$
where $u$ is the torque generated by the motor. If we discretize the system, given current angle $θ_t$ and angular velocity $θ'_t$, the angle and angular velocity at time $t + h$ can be calculated as $$θ_{t+h} = θ_t + h * θ'_t$$
$$θ'_{t+h} = θ'_t + h(−asinθ_t − b *θ'_t + u)$$
Now suppose we want the pendulum to stay upward (θ = π, or 180 degree). Given measurements of the current angle $θ$ and angular velocity $θ'$, how would you apply the motor torque $u$ to achieve this?
I know that when $θ =π $ the equilibrium point is unstable. So to make this point stable we add $u$. I don't know how to find the function of $u$.
You can apply a change of variables to your system $\tilde{\theta} = \theta-\pi$ so that $\tilde{\theta} = 0$ is an unstable point (if you look at the system without $u$). Then you just need to select your $u$ in such a way that the transformed system looks exactly like the old one (then $\tilde{\theta}=0$ will stable).