#include <vector>
#include <stdio.h>
#include <G4ParticleDefinition.hh>
#include "BLManager.hh"
#include "BLParam.hh"
#include "BLEvaluator.hh"
#include "BLCoordinates.hh"
#include "BLAsciiFile.hh"
Classes | |
class | BLCMDprofile |
class BLCMDprofile will print profile information at a list of Z positions. More... | |
struct | BLCMDprofile::Entry |
Functions | |
static double | determinant (double **a, int n) |
Variables | |
BLCMDprofile | defaultProfile |
static double determinant | ( | double ** | a, | |
int | n | |||
) | [static] |
Referenced by BLCMDprofile::callback().
00360 { 00361 int i,j,j1,j2 ; // general loop and matrix subscripts 00362 double det = 0 ; // init determinant 00363 double **m = NULL ; // pointer to pointers to implement 2d 00364 // square array 00365 00366 if (n < 1) { } // error condition, should never get here 00367 00368 else if (n == 1) { // should not get here 00369 det = a[0][0] ; 00370 } 00371 00372 else if (n == 2) { // basic 2X2 sub-matrix determinate 00373 // definition. When n==2, this ends the 00374 det = a[0][0] * a[1][1] - a[1][0] * a[0][1] ;// the recursion series 00375 } 00376 00377 00378 // recursion continues, solve next sub-matrix 00379 else { // solve the next minor by building a 00380 // sub matrix 00381 det = 0 ; // initialize determinant of sub-matrix 00382 00383 // for each column in sub-matrix 00384 for (j1 = 0 ; j1 < n ; j1++) { 00385 // get space for the pointer list 00386 m = (double **) malloc((n-1)* sizeof(double *)) ; 00387 00388 for (i = 0 ; i < n-1 ; i++) 00389 m[i] = (double *) malloc((n-1)* sizeof(double)) ; 00390 // i[0][1][2][3] first malloc 00391 // m -> + + + + space for 4 pointers 00392 // | | | | j second malloc 00393 // | | | +-> _ _ _ [0] pointers to 00394 // | | +----> _ _ _ [1] and memory for 00395 // | +-------> _ a _ [2] 4 doubles 00396 // +----------> _ _ _ [3] 00397 // 00398 // a[1][2] 00399 // build sub-matrix with minor elements excluded 00400 for (i = 1 ; i < n ; i++) { 00401 j2 = 0 ; // start at first sum-matrix column position 00402 // loop to copy source matrix less one column 00403 for (j = 0 ; j < n ; j++) { 00404 if (j == j1) continue ; // don't copy the minor column element 00405 00406 m[i-1][j2] = a[i][j] ; // copy source element into new sub-matrix 00407 // i-1 because new sub-matrix is one row 00408 // (and column) smaller with excluded minors 00409 j2++ ; // move to next sub-matrix column position 00410 } 00411 } 00412 00413 det += pow(-1.0,1.0 + j1 + 1.0) * a[0][j1] * determinant(m,n-1) ; 00414 // sum x raised to y power 00415 // recursively get determinant of next 00416 // sub-matrix which is now one 00417 // row & column smaller 00418 00419 for (i = 0 ; i < n-1 ; i++) free(m[i]) ;// free the storage allocated to 00420 // to this minor's set of pointers 00421 free(m) ; // free the storage for the original 00422 // pointer to pointer 00423 } 00424 } 00425 return(det) ; 00426 }