%% Convert State-Space Model to Modal Canonical Form
% pendulumCartSSModel.mat contains the state-space model of an inverted pendulum on a cart where the outputs are the cart displacement x and the pendulum angle \theta. The control input u is the horizontal force on the cart.
% \left[\begin{array}{c}
% \dot{x}\\
% \ddot{x}\\
% \dot{\theta}\\
% \ddot{\theta}\\
% \end{array}\right]\;=\;\left[\begin{array}{ccc}
% 0 & 1 & 0 & 0\\
% 0 & -0.1 & 3 & 0\\
% 0 & 0 & 0 & 1\\
% 0 & -0.5 & 30 & 0\\
% \end{array}\right] \left[\begin{array}{c}
% x\\
% \dot{x}\\
% \theta\\
% \dot{\theta}\\
% \end{array}\right]+\left[\begin{array}{c}
% 0\\
% 2\\
% 0\\
% 5\\
% \end{array}\right] u\\
% \;\;\;\;\;y\;=\;\left[\begin{array}{cccc}
% 1 & 0 & 0 & 0\\
% 0 & 0 & 1 & 0\\
% \end{array}\right] \left[\begin{array}{c}
% x\\
% \dot{x}\\
% \theta\\
% \dot{\theta}\\
% \end{array}\right]+\left[\begin{array}{c}
% 0\\
% 0\\
% \end{array}\right]u
% First, load the state-space model sys to the workspace.

load('pendulumCartSSModel.mat','sys');

% Convert sys to modal canonical form and extract the transformation matrix.

[csys,T] = canon(sys,'modal')

% csys is the modal canonical form of sys, while T represents the transformation between the state vectors of sys and csys.
% Copyright 2019 The MathWorks, Inc.
%