📄 matrix.java,v
字号:
// int c: number of columns in the matrix // // returns : none // // this function initialize the matrix // public int getNumColumns() { a86 1 d89 13a101 11 // method: copyLowerMatrix // // arguments: // Matrix A: inverse matrix // // returns : none // // this routine computes the inverse of a matrix // public void copyLowerMatrix(Matrix A) {d106 5a110 3 for (int i = 0; i < A.row; i++) { for (int j = 0; j <= i; j++) {a113 1d115 1a115 2 }d118 13a130 11 // method: getColSumSquare // // arguments: // Matrix A: inverse matrix // // returns : none // // this routine computes the inverse of a matrix // public double getColSumSquare(int col_a) {d136 2a137 1 for (int i = 0; i < row; i++) {a140 1d143 14a156 13 // method: setValue // // arguments: // double value_a: input set of points // int r: number of rows in the matrix // int c: number of columns in the matrix // // returns : none // // this function initialize the matrix // public void setValue(int r, int c, double value_a) { a157 1 d160 14a173 13 // method: getValue // // arguments: // double value_a: input get of points // int r: number of rows in the matrix // int c: number of columns in the matrix // // returns : none // // this function initialize the matrix // public double getValue(int r, int c) { a174 1 d177 14a190 13 // method: initMatrix // // arguments: // double initVal: input set of points // int r: number of rows in the matrix // int c: number of columns in the matrix // // returns : none // // this function initialize the matrix // public void initMatrixValue(int r, int c, double value_a, int type_a) { d197 4a200 2 for(int i = 0; i < row; i++) { for(int j = 0; j < col; j++) {d205 15a219 13 // method: initMatrix // // arguments: // double initVal: input set of points // int r: number of rows in the matrix // int c: number of columns in the matrix // // returns : none // // this function initialize the matrix // public void initMatrix(double initVal[][], int r, int c) {d226 4a229 2 for(int i = 0; i < row; i++) { for(int j = 0; j < col; j++) {d235 14a248 12 // method: initMatrix // // arguments: // double initVal: input set of points // int r: number of rows in the matrix // int c: number of columns in the matrix // // returns : none // // this function initialize the matrix // public void initMatrix(Vector vec_a) {d255 4a258 2 for(int i = 0; i < row; i++) { for(int j = 0; j < col; j++) {d263 15a277 14 // method: intDiagonalMatrix // // arguments: // double initVal: input set of points // int r: number of rows in the matrix // int c: number of columns in the matrix // // returns : none // // this function initialize the matrix // public void initDiagonalMatrix(Vector vec_a) {d283 2a284 1 for(int i = 0; i < row; i++) {d289 14a302 13 // method: getDiagonalVector // // arguments: // double initVal: input set of points // int r: number of rows in the matrix // int c: number of columns in the matrix // // returns : none // // this function initialize the matrix // public void getDiagonalVector(Vector vec_a) {d306 2a307 1 for(int i = 0; i < row; i++) {d312 14a325 12 // method: toVector // // arguments: // double initVal: input set of points // int r: number of rows in the matrix // int c: number of columns in the matrix // // returns : none // // this function initialize the matrix // public void toDoubleVector(Vector vec_a) {d329 2a330 1 if ( col == 1 ){d333 2a334 1 else if ( row == 1 ){d337 3a339 2 else { //System.out.println("Error in toDoubleVector");d345 4a348 2 for(int j = 0; j < size; j++) { if ( row == 1 ){d351 2a352 1 else {d357 14a370 12 // method: copyMatrix // // arguments: // Matrix A: matrix copy // // returns : none // // this routine takes a matrix as an argument and copies it to the // the matrix object that invoked it // public void copyMatrix(Matrix A) {d377 4a380 2 for(int i = 0; i < row; i++ ) { for(int j = 0; j < col; j++) {d386 13a398 11 // method: copyMatrix // // arguments: // Matrix A: matrix copy // // returns : none // // this routine takes a matrix as an argument and copies it to the // the matrix object that invoked it // public void copyMatrixRows(Matrix A, boolean[] flags_a) {d403 4a406 3 for (int i = 0; i < flags_a.length; i++ ){ if ( flags_a[i] ){d414 6a419 3 for (int i = 0; i < flags_a.length; i++ ){ if ( flags_a[i] ){ for ( int j = 0; j < col; j++ ){d426 12a437 9 // method: identityMatrix // // arguments: none // returns : none // // this routine creates a identity matrix // public void identityMatrix() {d445 6a450 3 for(int i = 0; i < row; i++ ) { for(int j = 0; j < col; j++) { if (i == j) {d457 15a471 13 // method: choleskySolve // // arguments: // MVector<TScalar, TIntegral>& out_vec: (output) output vector // const MMatrix<TScalar, TIntegral>& l: (input) lower triangular cholesky // decomposition matrix // const MVector<TScalar, TIntegral>& in_vec: (output) input vector // // return: a boolean value indicating status // // this method solves the linear equation l * l' * x = b, where L is the // cholesky decomposition matrix and b is an input vector. //d473 2a474 2 Matrix l_a, Matrix in_vec_a) {d480 3a482 3 //System.out.println("l_a nrows: " + nrows); //System.out.println("in_vec_a size: " + in_vec_a.getNumColumns());d486 2a487 2 for (int i = 0; i < nrows; i++) {d494 2a495 1 for (int j = i - 1; j >= 0; j--) {d498 1a498 1d503 1a503 1d506 2a507 2 for (int i = nrows - 1; i >= 0; i--) {d514 2a515 1 for (int j = i + 1; j < nrows; j++) {d518 1a518 1d523 1a523 1d529 18a546 17 // method: decompositionCholesky // // arguments: // const MMatrix<TScalar, TIntegral>& this: (input) input matrix // MMatrix<TScalar, TIntegral>& l: (output) lower triangular matrix // // return: a boolean value indicating status // // this method constructs the Cholesky decomposition of an input matrix: // // W. Press, S. Teukolsky, W. Vetterling, B. Flannery, // Numerical Recipes in C, Second Edition, Cambridge University Press, // New York, New York, USA, pp. 96-97, 1995. // // upon output, l' * l = this // note that this method only operates on symmetric matrices. //d593 2a594 1 for (int i = 0; i < nrows; i++) {d601 2a602 1 for (int j = i; j < nrows; j++) {d607 2a608 1 for (int k = i - 1; k >= 0; k--) {d614 3a616 2 if (i == j) {d620 3a622 2 if (sum <= 0.0) { //System.out.println("decompositionCholesky()");d633 2a634 1 else {d639 1a639 1 d645 1a645 1d647 1a647 1d649 18a666 16 // method: gaussj // // arguments: // double a: input matrix // int n: number of rows and columns in the input matrix // double b: output matrix // int m: number of rows and columns in the output matrix // // returns : none // // this routine computes the inverse matrix using the gauss jordan method // see numerical recipes, the are of scientific computing, second edition, // cambridge university press. pages 36 - 41 // public void gaussj(double a[][], int n, double b[][], int m) {d687 6a692 4 for (j=0;j<n;j++) ipiv[j]=0; for (i=0;i<n;i++) { big=0.0; for (j=0;j<n;j++)d694 9a702 6 for (k=0;k<n;k++) { if (ipiv[k] == 0) { if (Math.abs(a[j][k]) >= big) { big=Math.abs(a[j][k]); irow=j; icol=k;d704 5a708 3 } else if (ipiv[k] > 1) { return; }d711 13a723 10 if (irow != icol) { for (l=0;l<n;l++) { tmp=a[irow][l]; a[irow][l]=a[icol][l]; a[icol][l]=tmp; } for (l=0;l<m;l++) { tmp=b[irow][l]; b[irow][l]=b[icol][l]; b[icol][l]=tmp;d726 4a729 3 indxr[i]=irow; indxc[i]=icol; if (a[icol][icol] == 0.0) {d732 15a746 10 pivinv=1.0/a[icol][icol]; a[icol][icol]=1.0; for (l=0;l<n;l++) a[icol][l] *= pivinv; for (l=0;l<m;l++) b[icol][l] *= pivinv; for (ll=0;ll<n;ll++) if (ll != icol) { dum=a[ll][icol]; a[ll][icol]=0.0; for (l=0;l<n;l++) a[ll][l] -= a[icol][l]*dum; for (l=0;l<m;l++) b[ll][l] -= b[icol][l]*dum;d749 9a757 6 for (l=n-1;l>=0;l--) { if (indxr[l] != indxc[l]) { for (k=0;k<n;k++) { tmp=a[k][indxr[l]]; a[k][indxr[l]]=a[k][indxc[l]]; a[k][indxc[l]]=tmp;d762 13d776 2a777 12 // method: invertMatrix // // arguments: // Matrix A: inverse matrix // // returns : none // // this routine computes the inverse of a matrix // public void invertMatrix(Matrix A) { if ((A == null) || (row != col)) {d802 17a818 12 // method: resetMatrix // // arguments: none // returns : none // // this routine takes a matrix as an argument and copies it to the // the matrix object that invoked it // public void resetMatrix() { for(int i = 0; i < row; i++ ) { for(int j = 0; j < col; j++) {d824 12a835 10 // method: addMatrix // // arguments: // Matrix A: sum matrix // // returns : none // // this routine adding two matrices // public void addMatrix(Matrix A) {d837 2a838 1 if (A == null) {d842 2a843 1 if( (row != A.row) || (col != A.col) ) {d846 6a851 4 else { for(int i = 0; i < row; i++ ) { for(int j = 0; j < col; j++) {d858 13a870 11 // method: subtractMatrix // // arguments: // Matrix A: input matrix // Matrix B: difference matrix // // returns : none // // thid routine subtracts two matrices // public void subtractMatrix(Matrix A, Matrix B) {d872 2a873 1 if(A == null || B == null) {d877 2a878 1 if( (row != A.row) || (col != A.col) ) {d881 2a882 2 else {d887 4a890 2 for(int i = 0; i < row; i++ ) { for(int j = 0; j < col; j++) {d896 19a914 14 // method: scalarMultMatrix // // arguments: // double scalar: matrix scalar value // // returns : none // // this routine multiplys a matrix with a scalar // public void scalarMultMatrix(double scalar) { for(int i = 0; i < row; i++ ) { for(int j = 0; j < col; j++) {d920 17a936 13 // method: normMatrix // // arguments: // double scalar: matrix scalar value // // returns : none // // this routine multiplys a matrix with a scalar // public void normMatrix() { for(int i = 0; i < row; i++ ) { for(int j = 0; j < col; j++) {d942 17a958 13 // method: expMatrix // // arguments: // double scalar: matrix scalar value // // returns : none // // this routine multiplys a matrix with a scalar // public void expMatrix() { for(int i = 0; i < row; i++ ) { for(int j = 0; j < col; j++) {d963 18a980 14 // method: inverseMatrixElement // // arguments: // double scalar: matrix scalar value // // returns : none // // this routine multiplys a matrix with a scalar // public void inverseMatrixElements() { for(int i = 0; i < row; i++ ) { for(int j = 0; j < col; j++) {d986 17a1002 13 // method: addMatrixElement // // arguments: // double scalar: matrix scalar value // // returns : none // // this routine multiplys a matrix with a scalar // public void addMatrixElements(double val_a) { for(int i = 0; i < row; i++ ) { for(int j = 0; j < col; j++) {d1008 17a1024 14 // method: multMatrix // // arguments: // Matrix A: input matrix // Matrix B: product matrix // // returns : none // // this routine multiplys two matrices // public void multMatrix(Matrix A, Matrix B) { if(A == null || B == null) { //System.out.println(" A == null || B == null");d1030 3a1032 2 if(col != A.row ) { //System.out.println(" col != A.row ");d1037 2a1038 2 else {d1043 4a1046 2 for(int i = 0; i < B.row; i++ ) { for(int j = 0; j < B.col; j++) { d1048 2a1049 1 for(int k = 0; k < col; k++ ) {d1056 13d1070 2a1071 12 // method: transposeMatrix // // arguments: // Matrix B: matrix transpose // // returns : none // // this routine performs the transpose of a matrix // public void transposeMatrix(Matrix B) { if(B == null) {d1079 4a1082 2 for(int i = 0; i < row; i++ ) { for(int j = 0; j < col; j++) {d1088 34a1121 26 // method: printMatrix // // arguments: none // returns : none // // print the matrix contemts to STDOUT // public void printMatrix() {// for(int i=0; i<row; i++) {// for(int j=0; j<col; j++) {// //System.out.print(Elem[i][j] + " " );// }// //System.out.print("\n");// }// //System.out.print("\n"); } // method: printDoubleVector // // arguments: none // returns : none // // print the DoubleVector contemts to STDOUT // public static void printDoubleVector(Vector vec_a) {a1128 3//// end of file@1.2log@Algorithm Complete and debug statements commented@text@d971 1a971 1// }@1.1log@Initial revision@text@d310 1a310 1 System.out.println("Error in toDoubleVector");d564 1a564 1 System.out.println("decompositionCholesky()");d900 1a900 1 System.out.println(" A == null || B == null");d907 1a907 1 System.out.println(" col != A.row ");d964 8a971 8 for(int i=0; i<row; i++) { for(int j=0; j<col; j++) { System.out.print(Elem[i][j] + " " ); } System.out.print("\n"); } System.out.print("\n"); }@
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -