next up previous contents
Next: Cholesky factorising a general Up: General size matrices Previous: General size matrix/matrix multiplication   Contents

Inverting a general size matrix

If a general rectangular matrix $A$ happens to be square, it can be inverted using the routine
      Gan_Matrix mA, mB; /* declare matrices A & B */

      /* ... create and fill matrix A, which must be square, create B ... */
      gan_mat_invert_q ( &mA, &mB ); /* B = A^-1 */
There is also a routine to create the inverse matrix $A^{-1}$ from scratch:
      Gan_Matrix mA, *pmB; /* declare matrix A */

      /* ... create and fill matrix A, which must be square ... */
      pmB = gan_mat_invert_s ( &mA ); /* B = A^-1 */
The routines for special square matrices are similar
      Gan_Matrix mA, mB, *pmB; /* declare matrices A & B */

      /* ... create and fill matrix A, which must be square, create B ... */
      gan_squmat_invert_q ( &mA, &mB ); /* B = A^-1, OR */
      pmB = gan_squmat_invert_s ( &mA ); /* B = A^-1 */
The type of the output $B$ is in this case set to the appropriate type given the input. For all the square matrix types supported by Gandalf (symmetric, triangular, diagonal, scaled identity), the matrix type of the inverse $B$ is the same as that of the input matrix $A$.

Error detection: If implicit inverse is used (the ..._squmatI_...() or ..._squmatIT_...() routines), the square matrix involved must be non-singular. If the matrix is singular then NULL is returned and the Gandalf error handler is invoked. Other failure modes are failing to create the result matrix and incompatibility between the sizes of the input matrices.



2006-03-17