clear all;
clc;

% Array specification
a = [1 2 3 4 6 4]

% Integer and real numbers can be used in the same array 
a = [1 2 3 4.0 6 4]

% By default, the variables are doubles, even if they are written
% as integers

% In fact:
a = [1 2 3 4.01 6 4]

% Generally, the operations are applied to all the elements:
% add 2 to all the elements of a and store the result in b
b = a + 2

% Power of the elements of the array
c = b.^2;

% Graphical representation of the array values 
plot(b)
% The graph is customizable: several options are set to the default
% values, but can they be modified
grid on
axis([0 7 0 10])
plot(b,'r*')
plot(b,'g-o')

% There are several type of graph
bar(b)
xlabel('Sample #')
ylabel('Pounds')

% Both abscissas and ordinates can be specified
plot(b, c, 'o');

% For creating a matrix, the rows are separated using ';' 
A = [1 2 0; 2 5 -1]

% The matrix transpose is computed using the operator "'"
B = A'

% The matrix product is the "*" operator
C = A * B
% The matrices must be of suitable sizes;
% the command [1 2 3] * [2 3 4] causes an error

% The operator '.' makes operation element-wise
D = [1 2 3; 1 2 3].*[1 1 1; 2 2 2]

% The inverse of a matrix can be obtained by the inv() (or pinv()) function
X = inv(C)
% The product of a matrix and its inverse results in the identity 
I = inv(C) * C

%% Useful functions 
% List of the initialized variables (and their size) 
whos

% Delete all the variables in the workspace
clear all

% Particular matrices definition
ones(3,2) % all ones
zeros(3,2) % all zeros

% Sort the elements
sort([2 3 1 5 4])

% Compute the average 
mean([2 3 1 5 4])
% and the standard deviation
std([2 3 1 5 4])
