% P2
  disp(' ')
  disp('*************************************')
  disp(' ')
  disp(' Problem 2')
  disp(' ')
  
  randn('seed',0)
  rand('seed',0)
  p = 4;
  q = 10;
  n = p*q;
  G = zeros(n,n);
  for i=1:p
      rows = 1+(i-1)*q:i*q;
      G(rows,rows) = tril(rand(q,q),-1)+ eye(q,q);
      if i<p
         G(i*q+1,i*q) = rand;
      end
  end
  M = G*G';
  condM = cond(M)
  rhs = randn(n,1);
  xLongWay = M\rhs;
  A = cell(p,1);
  b = cell(p,1);
  f = zeros(p-1,1);
  for i=1:p
      rows = 1+(i-1)*q:i*q;
      A{i} = M(rows,rows);
      b{i} = rhs(rows);
      if i<p
          f(i) = M(i*q+1,i*q);
      end
  end
  x = BlockTriSolve(A,f,b);
  xVec = [];
  for i=1:p
      xVec = [xVec;x{i}];
  end
  error = norm(xVec - xLongWay)
  solution = reshape(xVec,10,4)
  
  
  
  