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