%ChE 216 Lab, 2/5/2009

%%
% defining matrices

A = [1,3,5;1,2,-6;0.4,2,pi];

disp(A);

% another way to define matrices

n = 5;
disp(n);

%optional, but faster; declare the size before
B = zeros(n);

for i=1:n
    for j=1:n
        B(i,j) = (-1)^(i+j)*(i^(n-j));
    end
end

%%
% Matrix functions
%
disp('B = ');
disp(B);

disp('det(B) = ');
disp(det(B));

disp('rank(B) = ');
disp(rank(B));

disp('size(B) = ');
disp(size(B));

disp('inv(B) = ');
disp(inv(B));
disp('eigenvalues of B:');
disp(eig(B));

[x,y] = eig(B);

disp('eigenvalues of B:');
disp(y);

disp('eigenvectors of B:');
disp(x);

%%
A = [1,-2,5;1,2,-6;0.4,2,pi];

C = [1,3,5;-3,2,4;-0.3,9,0];

%% Multiplying matrices
disp('A*C = ');
disp(A*C);

disp('C*A = ');
disp(C*A);

%% Augmenting matrices

%AC = [A C]
AC = [A C'];
disp('[A|C] = ');
disp(AC)

%% define a vector
D = [1,3,5];

%solve the matrix equation Ax=D
disp('Solution to Ax=D')

disp(D*inv(A))
disp(D/A)

