%Matlab Introduction
%Matrix Operations

close all
clear

a = rand(5)
b = randn(5)
c = randn(4,5)
% a is a random 5x5 matrix with elements uniform(0,1)
% b is same but elements from standard normal
% c is 4 rows and 5 columns

%%
%the $$ starts a new group, when we compile it stops here

a = [1 2 3; 4 5 6; 7 8 9]
b = [1 2 3; 4 5 6; 7 8 0]
det(a)
det(b)
%note the determinant of a should be zero, but isn't
%machine operations

%%
%we can calculate eigenvalues
eigs(a)
eigs(b)

%%
%we can do matrix operations
a = [1 2 3; 4 5 6; 7 8 9]
b = [1 0 0; 0 1 0; 0 0 1]
c = eye(3)
d = zeros(3)
%here eye gives an identity matrix, zeros a zero matrix
e = a * b
f = a .*b
%there is a difference; .* does component by component multiplication
e = a + b
%here is componentwise addition

%%
%let's solve some matrix equations
a = [1 2 3; 4 5 6; 7 8 0]
inv(a)
b = [1 2 3]
b' %transpose of b
size(a)
size(b)
size(b')
%these give sizes of a, b and  b'
inv(a) * b'