%% Solve for matrix X in AX = B

A = [1 2; 3 4]
B = [3 5; 7 9]

%% a good exam approach:
inv(A)
X = inv(A)*B

%% by hand, we could find A inv using
Aug = [A eye(2)]
rref(Aug)



%% a worse idea is to expand the AX term and form a new bigger system
pkg load symbolic   % skip on matlab
X = sym('x', [2 2])

A
A*X
equationsToMatrix(ans)
X(:)
B(:)


%% another way
Aug = [A B]
rref(Aug)
X = ans(:, [3 4])




%% Transform T from samples
B = [[1;4] [2;3]]
A = [[1;1] [-1;1]]

T = B*inv(A)

Aug = [transpose(A) transpose(B)]
rref(Aug)
TTr = ans(:,[3 4])
T = transpose(TTr)


%% Matrix diagonalization
A = rand(5,5); A = A + A'

[V,D] = eig(A)

A^17

V*D^17*inv(V)

D
D^17
