Main Page   Data Structures   File List   Data Fields   Globals  

matrix_invert.c

Go to the documentation of this file.
00001 #include        "sadie.h"
00002 
00003 /*-Copyright Information------------------------------------------------------*/
00004 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00005 /*----------------------------------------------------------------------------*/
00006 /*-General Information--------------------------------------------------------*/
00007 /*                                                                            */
00008 /*   This low-level function inverts a (non-singular) matrix.                 */
00009 /*                                                                            */
00010 /*----------------------------------------------------------------------------*/
00011 /*-Interface Information------------------------------------------------------*/
00012 void
00013 MATRIX_INVERT (double *mat,     /*  I   Pointer to the input matrix[size][size].              */
00014                short size,      /*  I   Size of the matrix.                                   */
00015                double *inv      /*  O   Pointer to the inverted matrix[size][size].           */
00016 /*----------------------------------------------------------------------------*/
00017   )
00018 {
00019   register short i, j, k;
00020   double temp;
00021 
00022   if (TIMES)
00023     TIMING (T_MATRIX_INVERT);
00024 
00025   /* copy imput matrix into output matrix */
00026   for (i = 0; i < size; i++)
00027     {
00028       for (j = 0; j < size; j++)
00029         {
00030           inv[i * size + j] = mat[i * size + j];
00031         }
00032     }
00033 
00034   /* perform inversion on inv, in place */
00035   for (i = 0; i < size; i++)
00036     {
00037       temp = inv[i * size + i];
00038       inv[i * size + i] = 1.0;
00039       for (j = 0; j < size; j++)
00040         {
00041           if (temp == 0.0)
00042             {
00043               MESSAGE ('E', " Can't invert singular matrix.");
00044               goto the_end;
00045             }
00046           else
00047             {
00048               inv[i * size + j] /= temp;
00049             }
00050         }
00051       for (j = 0; j < size; j++)
00052         {
00053           if (j != i)
00054             {
00055               temp = inv[j * size + i];
00056               inv[j * size + i] = 0.0;
00057               for (k = 0; k < size; k++)
00058                 {
00059                   inv[j * size + k] -= temp * inv[i * size + k];
00060                 }
00061             }
00062         }
00063     }
00064 
00065 the_end:
00066   if (TIMES)
00067     TIMING (T_EXIT);
00068 }

Generated on Sun May 18 15:36:12 2003 for tclSadie by doxygen1.3