%% ================== Matlab code fragment 8.1 ==================
A = [ 7 8 9 ; 4 5 6 ]
B = [ 10 40 ; 20 50 ; 30 60 ]
A*B
%% ================== Matlab code fragment 8.2 ==================
CX = [ 10 14 ; 14 20 ]
CXY = CX;
CW = eye(2) % 2 by 2 identity matrix
CY = CX + CW
format rat  % print numbers as ratios of small integers
A = CXY/CY
%% ================== Matlab code fragment 8.3 ==================
G = [ 1 -2 -2 1 0 ; 0 1 -1  3 -1 ; 1 3 3 -3 4 ; ...
      -1 1 2 1 -4 ; 0 2 0 -4 3 ];
C = G*G'
d = length(G);
n = 1000;
Z = randn(d,n); % Create d by n array of i.i.d. N(0,1) RVs
X = G*Z;        % Multiply each column by G
Chat = X*X'/n
%% ================== Matlab code fragment 8.4 ==================
A = [ 7 8 9 ; 4 5 6 ]
A'
%% ================== Matlab code fragment 8.5 ==================
G = [ 1 -2 -2 1 0 ; 0 1 -1 3 -1 ; 1 3 3 -3 4 ; ...
      -1 1 2 1 -4 ; 0 2 0 -4 3 ];
C = G*G'
d = length(G);
n = 1000;
m = [1:d]';     % Use an easy-to-define mean vector
Z = randn(d,n); % Create d by n array of i.i.d. N(0,1) RVs
X = G*Z;        % Multiply each column by G
X = X + repmat(m,1,n); % Add mean vec to each col of X
