% matrixOps.m 2011-11-14
% examples of useful MATLAB matrix calculations
%
clear;clc;
disp(sprintf(' MATLAB example: matrixOps.m'));
%
% Note: use a ';' after a line if you don't want MATLAB to display the
% calculation.

%Initialising a matrix:
A = [5 3 2; 4 6 1]
B = ones(3,2)
Z = zeros(3,3)
identity = eye(3)

% Matrix operations:
doubleA = A + A
doubleB = 2*B
transB = B'
B = A' + B
prodAB = A*B
prodBA = B*A

%element-by-element multiplication and division:
AtimesB = A.*transB
AdivB = A./transB

%determinant:
C = [8 5 3; 2 6 3; 1 1 9]
determinantC = det(C)

%inverse of a matrix:
inverseC = inv(C)

%concatenation:
E = [3; 4; 1];
D = [C E]

%Matrix reduction:
reduceD = rref(D)
