title: Calculate inverse of a non-square matrix in R
body: <p>I'm pretty new to the <strong>R</strong> language and trying to find out how you can calculate the inverse of a matrix that isn't square. (non-square? irregular? I'm unsure of the correct terminology).</p>
  
  <p>From my book and a quick google search, (see <a href="http://www.statmethods.net/advstats/matrix.html" rel="nofollow">source</a>), I've found you can use <code>solve(a)</code> to find the inverse of a matrix <strong>if</strong> <code>a</code> is square.</p>
  
  <p>The matrix I have created is, and from what I understand, not square:</p>
  
  <pre><code>  &gt; matX&lt;-matrix(c(rep(1, 8),2,3,4,0,6,4,3,7,-2,-4,3,5,7,8,9,11), nrow=8, ncol=3);
    &gt; matX
  
         [,1] [,2] [,3]
    [1,]    1    2   -2
    [2,]    1    3   -4
    [3,]    1    4    3
    [4,]    1    0    5
    [5,]    1    6    7
    [6,]    1    4    8
    [7,]    1    3    9
    [8,]    1    7   11
    &gt; 
  </code></pre>
  
  <p>Is there a function for solving a matrix of this size or will I have to do something to each element? as the <code>solve()</code> function gives this error:</p>
  
  <pre><code>  Error in solve.default(matX) : 'a' (8 x 3) must be square
  </code></pre>
  
  <p>The calculation I'm trying to achieve from the above matrix is: <code>(matX'matX)^-1</code></p>
  
  <p>Thanks in advance.</p>