Index of Functions: A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X
invert_c

 Procedure Abstract Required_Reading Keywords Brief_I/O Detailed_Input Detailed_Output Parameters Exceptions Files Particulars Examples Restrictions Literature_References Author_and_Institution Version Index_Entries

Procedure

invert_c ( Invert a 3x3 matrix )

void invert_c ( ConstSpiceDouble  m   ,
SpiceDouble       mout )

Abstract

Generate the inverse of a 3x3 matrix.

None.

MATH
MATRIX

Brief_I/O

VARIABLE  I/O  DESCRIPTION
--------  ---  --------------------------------------------------
m          I   Matrix to be inverted.
mout       O   Inverted matrix (m)^-1.

Detailed_Input

m           is an arbitrary 3x3 matrix. The limits on the size of
elements of `m' are determined by the process of calculating
the cofactors of each element of the matrix. For a 3x3
matrix this amounts to the differencing of two terms, each
of which consists of the multiplication of two matrix
elements. This multiplication must not exceed the range
of double precision numbers or else an overflow error will
occur.

Detailed_Output

mout        is the inverse of `m' and is calculated explicitly using
the matrix of cofactors. `mout' is set to be the zero matrix
if `m' is singular.

`mout' can overwrite `m'.

None.

Exceptions

1)  No internal checking on the input matrix `m' is performed except
on the size of its determinant. Thus it is possible to generate a
floating point overflow or underflow in the process of
calculating the matrix of cofactors.

2)  If the determinant is less than 10**-16, the matrix is deemed to
be singular and the output matrix is filled with zeros.

None.

Particulars

A temporary matrix is used to compute the result, so the output
matrix may overwrite the input matrix.

Examples

The numerical results shown for this example may differ across
platforms. The results depend on the SPICE kernels used as
input, the compiler and supporting libraries, and the machine
specific arithmetic implementation.

1) Given a double precision 3x3 matrix, compute its inverse. Check
that the original matrix times the computed inverse produces
the identity matrix.

Example code begins here.

/.
Program invert_ex1
./
#include <stdio.h>
#include "SpiceUsr.h"

int main( )
{

/.
Local variables.
./
SpiceDouble          imat   ;
SpiceDouble          mout   ;

SpiceInt             i;

/.
Define a matrix to invert.
./
SpiceDouble          m       = { {0.0, -1.0, 0.0},
{0.5,  0.0, 0.0},
{0.0,  0.0, 1.0} };

printf( "Original Matrix:\n" );
for ( i = 0; i < 3; i++ )
{

printf( "%16.7f %15.7f %15.7f\n", m[i], m[i], m[i] );

}

/.
Invert the matrix, then output.
./
invert_c ( m, mout );

printf( " \n" );
printf( "Inverse Matrix:\n" );
for ( i = 0; i < 3; i++ )
{

printf( "%16.7f %15.7f %15.7f\n",
mout[i], mout[i], mout[i] );

}

/.
Check the `m' times `mout' produces the identity matrix.
./
mxm_c ( m, mout, imat );

printf( " \n" );
printf( "Original times inverse:\n" );
for ( i = 0; i < 3; i++ )
{

printf( "%16.7f %15.7f %15.7f\n",
imat[i], imat[i], imat[i] );

}

return ( 0 );
}

When this program was executed on a Mac/Intel/cc/64-bit
platform, the output was:

Original Matrix:
0.0000000      -1.0000000       0.0000000
0.5000000       0.0000000       0.0000000
0.0000000       0.0000000       1.0000000

Inverse Matrix:
0.0000000       2.0000000      -0.0000000
-1.0000000       0.0000000      -0.0000000
0.0000000      -0.0000000       1.0000000

Original times inverse:
1.0000000       0.0000000       0.0000000
0.0000000       1.0000000       0.0000000
0.0000000       0.0000000       1.0000000

Restrictions

1)  The input matrix must be such that generating the cofactors will
not cause a floating point overflow or underflow. The
strictness of this condition depends, of course, on the computer
installation and the resultant maximum and minimum values of
double precision numbers.

None.

Author_and_Institution

N.J. Bachman        (JPL)
J. Diaz del Rio     (ODC Space)
W.M. Owen           (JPL)

Version

-CSPICE Version 1.1.0, 06-JUL-2021 (JDR)

Changed input argument name "m1" to "m" for consistency with
other routines.