% Example code for initialization of (dense) matrices in MATLAB
% I: direct initialization of small matrices. Here ; is the row separator
% (``line feed''), the comma the column separator (``space''). In fact, the
% comma can be replaced with a space
A = [1,2,3;4,5,6;7,8,9],
A', % \Red{Transpose} a matrix by the ' postfix operator!

% II: special matrices. Whenever two integer size arguments are given, the
% first is the number of rows, the second the number of columns
I = eye(3),     % identity matrix
Z = zeros(4,5), % zero matrix
E = ones(4,3),  % matrix containing all ones
D = diag([1,2,3,4]); % diagonal matrix with prescribed diagonal
R = rand(2,5) % matrix with i.i.d. random entries in $[0,1]$

% III: blockwise assembly of matrices, generalizing I
M = [0.5     , ones(1,4);...
    ones(4,1), D          ],

% IV: direct initialization of matrix entries, where the matrix size is
% increased automatically, which can be confusing and dangerous.
B(3,2) = 1; B(4,1) = -1; B, 
% Gobbles up the memory:
I = 9873; J = 3452; C(I,J) = 0;
whos C; % prints memory required by a variable
