Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

gaussian.c

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------- 00002 @COPYRIGHT : 00003 Copyright 1993,1994,1995 David MacDonald, 00004 McConnell Brain Imaging Centre, 00005 Montreal Neurological Institute, McGill University. 00006 Permission to use, copy, modify, and distribute this 00007 software and its documentation for any purpose and without 00008 fee is hereby granted, provided that the above copyright 00009 notice appear in all copies. The author and McGill University 00010 make no representations about the suitability of this 00011 software for any purpose. It is provided "as is" without 00012 express or implied warranty. 00013 ---------------------------------------------------------------------------- */ 00014 00015 #include <volume_io/internal_volume_io.h> 00016 #include <bicpl.h> 00017 00018 #ifndef lint 00019 static char rcsid[] = "$Header: /software/source//libraries/bicpl/Numerical/gaussian.c,v 1.7 2000/02/05 21:27:02 stever Exp $"; 00020 #endif 00021 00022 /* ----------------------------- MNI Header ----------------------------------- 00023 @NAME : scaled_maximal_pivoting_gaussian_elimination_float 00024 @INPUT : n 00025 coefs 00026 n_values 00027 values 00028 @OUTPUT : 00029 @RETURNS : TRUE if successful 00030 @DESCRIPTION: Finds the solution to coefs[n][n] * solution[n][n_values] = 00031 values[n_values][n] transposed, placing the 00032 solution in values. 00033 @METHOD : 00034 @GLOBALS : 00035 @CALLS : 00036 @CREATED : 1993 David MacDonald 00037 @MODIFIED : 00038 ---------------------------------------------------------------------------- */ 00039 00040 private BOOLEAN scaled_maximal_pivoting_gaussian_elimination_float( 00041 int n, 00042 float **coefs, 00043 int n_values, 00044 float **values ) 00045 { 00046 int i, j, v, *row; 00047 Real **a, **solution; 00048 BOOLEAN success; 00049 00050 ALLOC( row, n ); 00051 ALLOC2D( a, n, n ); 00052 ALLOC2D( solution, n, n_values ); 00053 00054 for_less( i, 0, n ) 00055 { 00056 for_less( j, 0, n ) 00057 a[i][j] = (Real) coefs[i][j]; 00058 for_less( v, 0, n_values ) 00059 solution[i][v] = (Real) values[v][i]; 00060 } 00061 00062 success = scaled_maximal_pivoting_gaussian_elimination( n, row, a, n_values, 00063 solution ); 00064 00065 if( success ) 00066 { 00067 for_less( i, 0, n ) 00068 { 00069 for_less( v, 0, n_values ) 00070 { 00071 values[v][i] = (float) solution[row[i]][v]; 00072 } 00073 } 00074 } 00075 00076 FREE2D( a ); 00077 FREE2D( solution ); 00078 FREE( row ); 00079 00080 return( success ); 00081 } 00082 00083 /* ----------------------------- MNI Header ----------------------------------- 00084 @NAME : solve_linear_system_float 00085 @INPUT : n 00086 coefs[n][n] 00087 values 00088 @OUTPUT : solution 00089 @RETURNS : TRUE if successful 00090 @DESCRIPTION: Solves the linear system of equations (coefs * solution = values). 00091 @METHOD : 00092 @GLOBALS : 00093 @CALLS : 00094 @CREATED : 1993 David MacDonald 00095 @MODIFIED : 00096 ---------------------------------------------------------------------------- */ 00097 00098 public BOOLEAN solve_linear_system_float( 00099 int n, 00100 float **coefs, 00101 float values[], 00102 float solution[] ) 00103 { 00104 int i; 00105 00106 for_less( i, 0, n ) 00107 solution[i] = values[i]; 00108 00109 return( scaled_maximal_pivoting_gaussian_elimination_float( n, coefs, 1, 00110 &solution ) ); 00111 } 00112 00113 /* ----------------------------- MNI Header ----------------------------------- 00114 @NAME : invert_square_matrix_float 00115 @INPUT : n 00116 matrix 00117 @OUTPUT : inverse 00118 @RETURNS : TRUE if successful. 00119 @DESCRIPTION: Computes the inverse of a square matrix of floats. 00120 @METHOD : 00121 @GLOBALS : 00122 @CALLS : 00123 @CREATED : 1993 David MacDonald 00124 @MODIFIED : 00125 ---------------------------------------------------------------------------- */ 00126 00127 public BOOLEAN invert_square_matrix_float( 00128 int n, 00129 float **matrix, 00130 float **inverse ) 00131 { 00132 float tmp; 00133 BOOLEAN success; 00134 int i, j; 00135 00136 for_less( i, 0, n ) 00137 { 00138 for_less( j, 0, n ) 00139 inverse[i][j] = 0.0f; 00140 inverse[i][i] = 1.0f; 00141 } 00142 00143 success = scaled_maximal_pivoting_gaussian_elimination_float( n, matrix, 00144 n, inverse ); 00145 00146 if( success ) 00147 { 00148 for_less( i, 0, n-1 ) 00149 { 00150 for_less( j, i+1, n ) 00151 { 00152 tmp = inverse[i][j]; 00153 inverse[i][j] = inverse[j][i]; 00154 inverse[j][i] = tmp; 00155 } 00156 } 00157 } 00158 00159 return( success ); 00160 }

Generated on Wed Jul 28 09:10:57 2004 for BICPL by doxygen 1.3.7