title: Inverse of a 4x3 matrix in python
body: <p>I'm reimplementing a closed source 3d library called noesis.</p>
  
  <p>It exposes a python file with all of the basic classes.</p>
  
  <p>All of the implementation details are actually hidden. The implementation is compiled so I can't preview it.</p>
  
  <p>I want to implement one of the fuctions from that library called mat43Inverse.</p>
  
  <p>I know normally it's not possible to inverse a 4x3 matrix, but this function exists. </p>
  
  <p>Sample usage from a noesis plugin:</p>
  
  <pre><code>#4x3 matrix
  class NoeMat43:
  
      # ...
  
      def inverse(self): #returns mat43
          return noesis.mat43Inverse(self)
  </code></pre>
  
  <p>source of exposed classes file: <a href="https://github.com/majimboo/mviewer/blob/master/noesis/plugins/python/inc_noesis.py#L478" rel="nofollow noreferrer">https://github.com/majimboo/mviewer/blob/master/noesis/plugins/python/inc_noesis.py#L478</a></p>
  
  <p>noesis module is a compiled cpython module. (<a href="https://github.com/majimboo/mviewer/blob/master/noesis/plugins/NoesisPython.dll" rel="nofollow noreferrer">https://github.com/majimboo/mviewer/blob/master/noesis/plugins/NoesisPython.dll</a>)</p>
  
  <pre><code>boneMtx = NoeMat43((
    NoeVec3((m01, m02, m03)),
    NoeVec3((m11, m12, m13)),
    NoeVec3((m21, m22, m23)),
    NoeVec3((m04, m14, m24))
  )).inverse()
  </code></pre>
  
  <p>I prepared a set of correct results by calling the native function and printing the result.</p>
  
  <pre><code>input = NoeMat43((
      NoeVec3((2.5, 3.6, 4.7)),
      NoeVec3((2.9, 3.1, 4.3)),
      NoeVec3((6.5, 7.6, 8.7)),
      NoeVec3((1.1, 9.4, 3.2))
  ))
  
  result = input.inverse()
  expected = NoeMat43((
      NoeVec3((0.04392901062965393, 0.05095765367150307, 0.1142154261469841)),
      NoeVec3((0.044815145432949066, 0.038590818643569946, 0.09460975229740143)),
      NoeVec3((0.04042314738035202, 0.036982882767915726, 0.07482582330703735)),
      NoeVec3((-0.8928132057189941, -0.714801549911499, -0.6315471529960632))
  ))
  noeassert('mat43Inverse', result, expected)
  </code></pre>
  
  <p><strong>Correct results</strong></p>
  
  <p>1.</p>
  
  <pre><code>input: (
  (1, 0, 0),
  (0, 1, 0),
  (0, 0, 1),
  (0, 0, 0)
  )
  
  inverse result: (
  (1.0, 0.0, 0.0),
  (0.0, 1.0, 0.0),
  (0.0, 0.0, 1.0),
  (0.0, 0.0, 0.0)
  )
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>input: (
  (2.5, 3.6, 4.7),
  (2.9, 3.1, 4.3),
  (6.5, 7.6, 8.7),
  (1.1, 9.4, 3.2)
  )
  
  invserse result: (
  (0.04392901062965393, 0.05095765367150307, 0.1142154261469841),
  (0.044815145432949066, 0.038590818643569946, 0.09460975229740143),
  (0.04042314738035202, 0.036982882767915726, 0.07482582330703735),
  (-0.8928132057189941, -0.714801549911499, -0.6315471529960632)
  )
  </code></pre>
  
  <p>3.</p>
  
  <pre><code>input: (
  (0.0, 0.0, 1.0),
  (0.0, 1.0, 0.0),
  (-1.0, 0.0, 0.0),
  (0.0, 32.29199981689453, -3.2665998935699463)
  )
  
  inverse result: (
  (0.0, 0.0, -1.0),
  (0.0, 1.0, 0.0),
  (1.0, 0.0, 0.0),
  (-3.2665998935699463, -32.29199981689453, 0.0)
  )
  </code></pre>
  
  <p>4.</p>
  
  <pre><code>input: (
  (0.0, 0.0, 2.0),
  (0.0, 2.0, 0.0),
  (-2.0, 0.0, 0.0),
  (0.0, 32.29199981689453, -3.2665998935699463)
  )
  
  inverse result: (
  (0.0, 0.0, -0.5),
  (0.0, 0.5, 0.0),
  (0.5, 0.0, 0.0),
  (-1.6332999467849731, -16.145999908447266, 0.0)
  )
  </code></pre>
  
  <p>5.</p>
  
  <pre><code>input: (
  (2.0, 0.0, 2.0),
  (0.0, 2.0, 0.0),
  (-2.0, 0.0, 0.0),
  (0.0, 32.29199981689453, -3.2665998935699463)
  )
  
  inverse result: (
  (0.2499999850988388, 0.0, -0.2499999850988388),
  (0.0, 0.5, 0.0),
  (0.5, 0.0, 0.0),
  (-0.8166499137878418, -16.145999908447266, 0.0)
  )
  </code></pre>
  
  <p><strong>Questions:</strong></p>
  
  <ul>
  <li>What is the formula behind mat43Inverse function?</li>
  </ul>