title: Fast and efficient upper diagonal matrix inverse
body: <p>I compute the <a href="http://en.wikipedia.org/wiki/Multivariate_normal_distribution" rel="nofollow">multinomial Gaussian</a> density for some huge number of times in a project where I update the covariance matrix by rank-1. Instead of computing the covariance from scratch, I used the <code>cholupdate</code> function to add a new sample to the covariance and remove a new sample to the covariance. By this way, the update is told to be in $O(n^2)$ as opposed to $O(n^3)$ Cholesky factorization of the covariance matrix.</p>
  
  <pre><code>persistent R
  if (initialize) % or isempty(R)
      % compute covariance V
      R = chol(V);
  else
      R = cholupdate(R,xAdded);
  
  detVar = prod(diag(R))^2;
  Rt = R';
  coeff = 1/sqrt((2*pi)^dimension*detVar);
  y = Rt\x;
  logp = log(coeff) - 1/2 * norm(y)^2;
  </code></pre>
  
  <p>Actually the code is quite complicated but I simplified it here. I wonder if there is a faster way to compute the inverse (the <code>Rt\x</code> part in the code) of an upper triangular matrix in MATLAB. Do you have any ideas to do it more efficiently in MATLAB.</p>
  
  <p>Note that computing the determinant is also faster this way. So the new method will also not bad for the computation of the determinant.</p>