- public class MyCholeskyDecomposition {
- /**
- * 2.0000000000 0.0000000000 0.0000000000
- * 0.5000000000 1.3228756555 0.0000000000
- * 0.5000000000 2.0788046016 1.1952286093
- * @param args
- */
- public static void main(String[] args) {
- double[][] A = {
- {
- 4.,1.,1.
- },{
- 1.,2.,3.
- },{
- 1.,3.,6.
- }
- };
- double[][] L = new double[3][3];
- for(int m = 0; m < A.length; m++){
- for(int n = 0; n <= m; n++){
- L[m][n] = A[m][n];
- for(int k = 0; k < n; k++){
- L[m][n] -= L[m][k] * L[n][k];
- }
- if(m == n){
- L[m][n] = Math.sqrt(L[m][n]);
- }else{
- L[m][n] = L[m][n] / L[n][n];
- }
- }
- for(int x = m + 1; x < A.length; x++){
- L[m][x] = 0.0;
- }
- }
- for(int i = 0; i < L.length; i++){
- for(int j = 0; j < L.length; j++){
- System.out.print(L[i][j] + " ");
- }
- System.out.println();
- }
- }
- }
来源: http://www.bubuko.com/infodetail-3526320.html