mDet.c
Go to the documentation of this file.
00001 /*******************************************************
00002  *
00003  * Author: Shinsaku Hiura, Hirokazu Kato
00004  *
00005  *         shinsaku@sys.es.osaka-u.ac.jp
00006  *         kato@sys.im.hiroshima-cu.ac.jp
00007  *
00008  * Revision: 2.1
00009  * Date: 99/07/16
00010  *
00011 *******************************************************/
00012 #include <stdio.h>
00013 #include <math.h>
00014 #include <AR/matrix.h>
00015 
00016 #define MATRIX(name,x,y,width)  ( *(name + (width) * (x) + (y)) )
00017 
00018 static double mdet( double *ap, int dimen, int rowa );
00019 
00020 double arMatrixDet(ARMat *m)
00021 {
00022 
00023         if(m->row != m->clm) return 0.0;
00024 
00025         return mdet(m->m, m->row, m->row);
00026 }
00027 
00028 
00029 
00030 static double mdet(double *ap, int dimen, int rowa)
00031 /*  double  *ap;          input matrix */
00032 /*  int     dimen;        Dimension of linre and row, those must be equal,
00033                           that is square matrix.       */
00034 /*  int     rowa;         ROW Dimension of matrix A    */
00035 {
00036     double det = 1.0;
00037     double work;
00038     int    is = 0;
00039     int    mmax;
00040     int    i, j, k;
00041 
00042     for(k = 0; k < dimen - 1; k++) {
00043         mmax = k;
00044         for(i = k + 1; i < dimen; i++)
00045             if (fabs(MATRIX(ap, i, k, rowa)) > fabs(MATRIX(ap, mmax, k, rowa)))
00046                 mmax = i;
00047         if(mmax != k) {
00048             for (j = k; j < dimen; j++) {
00049                 work = MATRIX(ap, k, j, rowa);
00050                 MATRIX(ap, k, j, rowa) = MATRIX(ap, mmax, j, rowa);
00051                 MATRIX(ap, mmax, j, rowa) = work;
00052             }
00053             is++;
00054         }
00055         for(i = k + 1; i < dimen; i++) {
00056             work = MATRIX(ap, i, k, rowa) / MATRIX(ap, k, k, rowa);
00057             for (j = k + 1; j < dimen; j++)
00058                 MATRIX(ap, i, j, rowa) -= work * MATRIX(ap, k, j, rowa);
00059         }
00060     }
00061     for(i = 0; i < dimen; i++)
00062         det *= MATRIX(ap, i, i, rowa);
00063     for(i = 0; i < is; i++) 
00064         det *= -1.0;
00065     return(det);
00066 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


ar_recog
Author(s): Graylin Trevor Jay and Christopher Crick
autogenerated on Fri Jan 25 2013 12:15:00