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 MATRIX_INVERT (
00013 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 ) { register short i, j, k;
00018     double temp;
00019 
00020     if (TIMES) TIMING(T_MATRIX_INVERT);
00021 
00022     /* copy imput matrix into output matrix */
00023     for (i=0; i<size; i++) {
00024         for (j=0; j<size; j++) {
00025             inv[i*size+j] = mat[i*size+j];
00026         }
00027     }
00028 
00029     /* perform inversion on inv, in place */
00030     for (i=0; i<size; i++) {
00031         temp = inv[i*size+i];
00032         inv[i*size+i] = 1.0;
00033         for (j=0; j<size; j++) {
00034             if (temp == 0.0) {
00035                 MESSAGE('E'," Can't invert singular matrix.");
00036                 goto the_end;
00037             } else {
00038                 inv[i*size+j] /= temp;
00039             }
00040         }
00041         for (j=0; j<size; j++) {
00042             if (j != i) {
00043                 temp = inv[j*size+i];
00044                 inv[j*size+i] = 0.0;
00045                 for (k=0; k<size; k++) {
00046                     inv[j*size+k] -= temp*inv[i*size+k];
00047                 }
00048             }
00049         }
00050     }
00051 
00052     the_end:
00053     if (TIMES) TIMING(T_EXIT);
00054 }

Generated on Wed Apr 9 08:56:08 2003 for TREES by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002