While paused, move the sliders to update the result instantly.
Cart mass M=1.0 kg, pendulum mass m=0.1 kg, length L=0.5 m, gravity g=9.81 m/s², simulation time 5 s (dt=0.01 s, RK4 integration).
Optimal state feedback u=−Kx restores the cart (blue) and pendulum (orange) to upright. The lower strip shows angle θ and control input u over time; a disturbance is applied periodically so you can watch the recovery.
Small-angle linearized cart-pole model with state $x=[p,\dot p,\theta,\dot\theta]^\top$ and input $u$ (horizontal cart force):
$$\dot x = A x + B u,\quad A=\begin{bmatrix}0&1&0&0\\0&0&-\tfrac{mg}{M}&0\\0&0&0&1\\0&0&\tfrac{(M+m)g}{ML}&0\end{bmatrix},\ B=\begin{bmatrix}0\\ \tfrac{1}{M}\\0\\ -\tfrac{1}{ML}\end{bmatrix}$$LQR finds the state-feedback gain that minimizes the quadratic cost $J=\int_0^\infty(x^\top Q x + u^\top R u)\,dt$:
$$u = -K x,\qquad K = R^{-1} B^\top P$$$P$ is the symmetric positive-definite solution of the algebraic Riccati equation $A^\top P + PA - PBR^{-1}B^\top P + Q = 0$.
For pedagogy this tool uses a baseline gain K=[-1, -1.5, -30, -5] (u=-Kx sign convention) linearly scaled by √(Q/R) rather than solving the Riccati equation in the browser.