function p1_writeup()

function LAMBDA = makeRandomCovarianceMatrix(dims, zeroidxs)
% this function returns a random covariance matrix of dimensions 'dims'
% (ie, one that is symmetric, positive semidefinite)
% where there are zeros at the indexes specified by 
% zeroidxs
  notposdef = 1;

  % choose a random pos semi definite matrix
  while (notposdef > 0),
    LAMBDA = rand(dims);

    % make it symmetric
    LAMBDA = LAMBDA - tril(LAMBDA) + triu(LAMBDA)';

    LAMBDA(zeroidxs) = 0;
    [x notposdef] = chol(LAMBDA);
  end;
end;

  NUM_SAMPLES = 50;

  LAMBDA = makeRandomCovarianceMatrix([5,5],[2 4 5 6 8 10 12 15 16 21 22 23])
  mu = zeros(size(LAMBDA,1),1)';
  samples = gausssamp(mu,inv(LAMBDA),NUM_SAMPLES);

  % MIXTURE OF GAUSSIAN COVARIANCE ESTIMATE
  INV_MLMIXCOV = inv(cov(samples))
  % ERROR
  INV_MIXCOV_DIFFERENCE = INV_MLMIXCOV - LAMBDA
  INV_MIXCOV_ERROR = sum(sum(abs(INV_MIXCOV_DIFFERENCE)))

  % 
  x1x3 = inv(cov(samples(:,[1 3])));
  x2x4 = inv(cov(samples(:,[2 4])));
  x3x4 = inv(cov(samples(:,[3 4])));
  x4x5 = inv(cov(samples(:,[4 5])));
  x3x3 = inv(cov(samples(:,[3])));
  x4x4 = inv(cov(samples(:,[4])));
  x5x5 = inv(cov(samples(:,[5])));
  
  % now form new estimate of covariance matrix
  MC = zeros(5,5);
  MC(1,1) = x1x3(1,1);
  MC(1,3) = x1x3(1,2);
  MC(2,2) = x2x4(1,1);
  MC(2,4) = x2x4(1,2);
  MC(3,3) = x1x3(2,2) + x3x4(1,1) - x3x3;
  MC(3,4) = x3x4(1,2);
  MC(4,4) = x2x4(2,2) + x3x4(2,2) + x4x5(1,1) - x4x4 - x4x4;
  MC(4,5) = x4x5(1,2);
  MC(5,5) = x4x5(2,2);
  MC = MC - tril(MC) + triu(MC)';

  MODELCONV = MC
  MODELERROR = sum(sum(abs(MODELCONV - LAMBDA)))
end