public class Arranger {
private double[][] arrangerMatrix;
private double arrangerResult=1.0;
public static void main(String args[]){
double[][] a={{4,1,4,8},{1,1,3,2},{2,2,5,1},{2,2,1,4}};
Arranger ar=new Arranger();
ar.arrFunction(a);//把行列式变成上三角行列式
ar.displayMatrix();//显示得出的上三角行列式
ar.displayResult();//显示行列式计算结果
}
public void arrFunction(double[][] a){//Guass 消去
double k=0;
for (int p = 0; pfor (int r =p+1; rk=a[r][p]/a[p][p];
a[r][p]=0;
for (int c = p+1; ca[r][c]=a[r][c]-k*a[p][c];
}//u
}//r
}//c
arrangerMatrix=new double[a.length][a[0].length];
for (int i = 0; ifor (int j = 0; jarrangerMatrix[i][j]=a[i][j];
if (i==j) {arrangerResult=arrangerResult*a[i][j];}//计算主对角线相乘的结果
//System.out.println (a[i][j]+" ");
}//j
}//i
}
public void displayMatrix(){
for (int i = 0; ifor (int j = 0; jSystem.out.print (arrangerMatrix[i][j]+" ");
}//j
System.out.println ();
}//i
}
public void displayResult(){
System.out.println ("The result is "+arrangerResult);
}