// Authors: Unknown. Please, if you are the author of this file, or if you // know who are the authors of this file, let us know, so we can give the // adequate credits and/or get the adequate authorizations. #include "numerics1.h" float **allocate_float_matrix(int nrows, int ncols) { float ** matrix; matrix = new float*[nrows]; for(int i=0; i < nrows; i++) matrix[i] = new float[ncols]; return matrix; } void desallocate_float_matrix(float **matrix, int nrows, int ncols) { if (matrix == NULL) return; for(int i=0; i < nrows; i++) { delete[] matrix[i]; matrix[i] = 0;} matrix = 0; ncols = ncols; // to remove the warning unused parameter ¡®ncols¡¯ } // ********************************************** // LU based algorithms // ********************************************** // Solves Ax=b by using lu decomposition int lusolve(float **a, float *x, float *b, int n) { float d; int *indx = new int[n]; if (ludcmp(a,n,indx,&d)) { for(int i=0; i < n; i++) x[i] = b[i]; lubksb(a,n,indx,x); delete[] indx; /*memcheck*/ return 1; } else { printf("lusolve::lu decomposition failed\n"); delete[] indx; /*memcheck*/ return 0; } delete[] indx; // Guoshen Yu } int ludcmp(float **a, int n, int *indx, float *d) { int i,imax=0,j,k,aux; float big,dum,sum,temp; float *vv; vv=(float *) malloc(n*sizeof(float)); *d=1.0; for(i=0;ibig ) big=temp; if (big==0.0) { return 0; printf("LU Decomposition failed\n");} vv[i]=1.0/big; } for(j=0;j=big){ big=dum; imax=i; } } if (j != imax){ for(k=0;k=0;i--){ sum=aux[i]; for(j=i+1;j