public class Matrixrank {public static int Rank (double[][] matrix,int error_,int List) {int n=list;
int m=matrix.length;
int i=0;
int i1;
int j=0;
int J1;
Double Temp1;
if (m>n) {i=m;
M=n;
N=i;
I=1;
} m-=1;
N-=1;
Double[][]temp=new double[m+1][n+1];
if (i==0) {for (i=0;i<=m;i++) {for (j=0;j<=n;j++) {temp[i][j]=matrix[i][j]; }} else {for (i=0;i<=m;i++) {for (j=0;j<=n;j++) {Temp[i][j]=ma
Trix[j][i];
}} if (m==0) {i=0;
while (i<=n) {if (matrix[0][i]!=0) {return 1;
} i+=1;
return 0;
Double error0;
if (error_==-1) {Error0=math.pow (0.1, 10);
else {Error0=math.pow (0.1, error_);
} i=0;
while (i<=m) {j=0;
while (j<=n) {if (temp[i][j]!=0) { ERROR0*=TEMP[I][J];
I=m;
Break
} j+=1;
} i+=1;
Double Error1;
for (i=0;i<=m;i++) {j=0;
while (j<=n) {if (temp[i][j]!=0) {break;
} j+=1;
} if (j<=n) {i1=0;
while (i1<=m) {if (temp[i1][j]!=0&&i1!=i) {temp1=temp[i][j]/temp[i1][j];
Error1=math.abs ((TEMP[I][J]-TEMP[I1][J]*TEMP1)) *100;
Error1+=error0;
for (j1=0;j1<=n;j1++) {temp[i1][j1]=temp[i][j1]-temp[i1][j1]*temp1;
if (Math.Abs (temp[i1][j1]) <error1) {temp[i1][j1]=0;
}} i1+=1;
}} i1=0;
for (i=0;i<=m;i++) {for (j=0;j<=n;j++) {if (temp[i][j]!=0) {i1+=1;
Break
}} return i1; public static void Main (String[]args)//test {double[][] TestmatrIX = {1, 22, 34,22}, {1, 11,5,21}, {0,1,5,11}, {7,2,13,19}};
double[][]testmatrix2={{1,2,3},{4,7,8},{2,9,1}};
double[][]testmatrix3={{1,2},{3,3}};
String strr=string.valueof (Rank (testmatrix,-1,4));
String strr2=string.valueof (Rank (testmatrix2,-1,3));
String strr3=string.valueof (Rank (testmatrix3,-1,2));
System.out.println (STRR);
System.out.println (STRR2);
System.out.println (STRR3);
}
}
Run Result:
Recommended articles: Those years, do a few applications