I am studying a tutorial about pendulum-on-a-cart control on youtube and its purpose is to stabilise the pendulum at the upper position where $\theta=\pi$. The state-vector is $$\mathbf{x}=\begin{bmatrix} \chi \\ \dot{\chi}\\ \theta \\ \dot{\theta}\\ \end{bmatrix}$$ Therefore, we linearise about $$\mathbf{x}=\begin{bmatrix} 0 \\ 0\\ \pi\\ 0\\ \end{bmatrix}$$ , and use the pole-placement command on Matlab to choose arbitrarily some set of admissible eigenvalues.
m = 1;M = 5;L = 2;g = 10;d = 1;
A = [0 1 0 0;
0 -d/M m*g/M 0;
0 0 0 1;
0 -d/(M*L) (m+M)*g/(M*L) 0];
B = [0; 1/M; 0; 1/(M*L)];
p = [-1.0;-1.1;-1.2;-1.3];
K = place(A,B,p);
To verify that the specific K does indeed do the job, we cal introduce the $u=K(y-r)$ back to the system and see how angle $\theta$ changes in time:
tspan = 0:0.001:10;
reference = [0; 0; pi; 0];
y0 = [0; 0; pi+.01; 0];
[t,y] = ode45(@(t,y)model(y,m,M,L,g,d,-K*(y-reference)),tspan,y0);
x = y(:,1);
x_dot = y(:,2);
theta = y(:,3);
theta_dot = y(:,4);
figure()
plot(t,theta);axis equal;xlabel('time');ylabel('theta');
If we introduce it to the full nonlinear system:
function dydt = model(y,m,M,L,g,d,u)
a = 1/(M+m-m*(cos(y(3)))^2);
dydt(1,1) = y(2);
dydt(2,1) = a*(g*sin(y(3))*cos(y(3)) + m*L*(y(4)^2)*sin(y(3)) - y(2)*d + u);
dydt(3,1) = y(4);
dydt(4,1) = (a/L)*(-(m+M)*g*sin(y(3)) - m*L*(y(4)^2)*sin(y(3))*cos(y(3)) + y(2)*cos(y(3))*d - u*cos(y(3)));
end
If instead we introduce it to the linearized version:
function dydt = model(y,m,M,L,g,d,u)
dydt(1,1) = y(2);
dydt(2,1) = (-d/M)*y(2) + (m*g/M)*y(3) + (1/M)*u;
dydt(3,1) = y(4);
dydt(4,1) = (-d/(M*L))*y(2) + ((m+M)*g/(M*L))*y(3) + (1/(M*L))*u;
end
, the result is this:
The pendulum never returns close to the reference, and practically goes all the way down to the stable equilibrium. Why does this happen? I would expect similar results, since the linearized version is valid and since the chosen eigenvalues and initial conditions are not unrealistic.

The dynamics of a nonlinear system $\dot{x}=f(x,u)$ can be approximated with a linearization using
$$ \dot{x} \approx \left.\frac{\partial\,f(x,u)}{\partial\,x}\right|_{\bar{x},\bar{u}} (x - \bar{x}) + \left.\frac{\partial\,f(x,u)}{\partial\,u}\right|_{\bar{x},\bar{u}} (u - \bar{u}), $$
with $\bar{x}$ and $\bar{u}$ the values of $x$ and $u$ respectively at the operating point, such that $f(\bar{x},\bar{u})=0$.
In your implementation for the linearized system you multiplied the partial derivatives with $x$ (and $u$) instead of $x-\bar{x}$ (and $u-\bar{u}$).