%% First steps with eigenvalues
% Let's create a matrix
% Note that a state-space matrix is always square (why?)
A = [1, 2; 2, 4]
% By default, the eig() function just gives us a vector of the eigenvalues
% but we can ask for both the eigenvectors and eigenvalue matrix like this:
[V, D] = eig(A)
% The original matrix is given by:
result = V * D * inv(V)
%% Visualizing eigenvalues and eigenvectors
% Reuse A from above, or make a new one if you prefer
A = [1, 2; 2, 1]
% Generate a bunch of random points
X = randn(2, 10000);
% Keep only the ones with a norm < 1 (i.e., in the unit circle)
X(:, vecnorm(X) > 1) = [];
% Now
Y = A * X;
plot(X(1,:), X(2,:), 'bx');
hold on;
plot(Y(1,:), Y(2,:), 'rx');
axis equal;
%% Questions for exploration:
% * Can you make a matrix where the eigenvalues are all less than 1? What
% does this mean in state space?
% * Can you make a matrix where the eigenvalues are all greater than 1?
% * What happens to the eigenvalues if the matrix is not full rank? (aka,
% rank-deficient?)