package Mat;
public class Matrix {
public static void printBoolMatrix(boolean array[][]) {
int rowLength = array[0].length;
int couLength = array.length;
for(int i=0;i != couLength;i++) {
for(int j=0;j != rowLength;j++) {
if(array[i][j] == true)
System.out.print("*"+" ");
else
System.out.print(" "+" ");
}
System.out.print("\n");
}
}
public static double dotVector(double[] a,double[] b) {
double Dot = 0.0;
for(int i=0;i != a.length;i++) {
Dot += a[i]*b[i];
}
return Dot;
}
public static double[][] transMatrix(double[][] a){
int couLength = a.length;
int rowLength = a[0].length;
double[][] c = new double[rowLength][couLength];
for(int i=0;i != couLength;i++) {
for(int j=0;j != rowLength;j++) {
c[j][i] = a[i][j];
}
}
return c;
}
public static double[][] multMatrix(double[][] a,double[][] b){
int couLength_a = a.length;
int couLength_b = b.length;
int rowLength_a = a[0].length;
int rowLength_b = b[0].length;
if(rowLength_a != couLength_b)
return null;
double[][] b_trans = transMatrix(b);
double[][] result = new double[couLength_a][rowLength_b];
for(int i=0;i != couLength_a;i++) {
for(int j=0;j != rowLength_b;j++) {
result[i][j] = dotVector(a[i], b_trans[j]);
}
}
return result;
}
public static double[] multMatVec(double[][] a,double[] b) {
int couLength = a.length;
if(a[0].length != b.length)
return null;
double[] c = new double[b.length];
for(int i=0;i != couLength; i++) {
c[i] = dotVector(a[i], b);
}
return c;
}
public static double[] multVecMat(double[][] a,double[] b) {
int couLength = a.length;
int rowLength = a[0].length;
double[] c = new double[b.length];
double[][] aTrans = transMatrix(a);
if(couLength != b.length)
return null;
for(int i=0;i != rowLength; i++) {
c[i] = dotVector(aTrans[i], b);
}
return c;
}
public static void main(String[] args) {
boolean boolTest[][] ={{true,false,true},
{false,true,true}};
printBoolMatrix(boolTest);
}
}