title: Giving an element from lower/upper triangular matrix
body: <p>I have the upper triangular portion of a matrix, with the main diagonal stored as a linear array, how can the (i,j) indices of a matrix element be extracted from the linear index of the array?</p>
  
  <p>For example the linear array :<code>[a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10]</code>is storage for the matrix</p>
  
  <pre><code>a0  a1  a2  a3
  0   a4  a5  a6
  0   0   a7  a8
  0   0   0   a10
  </code></pre>
  
  <p>I've found solutions for this problem but without the main diagonal which is:</p>
  
  <pre><code>index = (n*(n-1)/2) - (n-i)*((n-i)-1)/2 + j - i - 1
  </code></pre>
  
  <p>And solution for the same problem but for a lower triangular matrix with the diagonal:</p>
  
  <pre><code>index = ((i + 1) * i / 2 + i).
  </code></pre>
  
  <p>Regards,</p>