title: Trouble calculating product of upper triangular matrix using 1-D array (c++)
body: <p>I'm trying to multiply two upper triangular matrices together. The matrices are stored in single dimensional arrays instead of the usual 2-D arrays by omitting the zeros that would be under the diagonal (to conserve space). I've figured out how to map elements given a pair of indices to the index for the single array. but I'm having trouble with the actual calculation (The calculation works for smaller n x n square matrices, but for some reason gives incorrect results for larger n x n matrices). I believe that I might be passing in incorrect parameters to the <code>getValue()</code> function, but I think they should be right considering the general formula for matrix multiplication. Any help will be appreciated!</p>
  
  <p>Here's my relevant code:</p>
  
  <pre><code>// mat is an array containing the upper triangle data for a square matrix of size n
  // returns element at (i,j), or 0 for the lower triangle
  int val(int *mat, int n, int i, int j)
  {
    if (i &gt; j) {
      return 0; // lower triangle
    } else {
      return mat[j + (i*n) - i*(i+1)/2];
    }
  }
  </code></pre>