multiplicationmatrice
public class Matrices {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
double mat1[][]= new double [2][2];
double mat2[][]= new double [2][2];
mat1[0][0]=1;
mat1[0][1]=2;
mat1[1][0]=3;
mat1[1][1]=5;
mat2[0][0]=4;
mat2[0][1]=6;
mat2[1][0]=4;
mat2[1][1]=7;
double[][] prod =
new double[mat1.length][mat2[0].length];
for (int row = 0; row < mat1.length; row++) {
for (int col = 0; col < mat2[0].length; col++) {
prod[row][col] = 0.0;
for (int i = 0; i < mat2.length; i++) {
prod[row][col] += mat1[row][i] *
mat2[i][col];
}
}
}
for (int i=0;i<2;i++)
{
for (int j=0;j<2;j++)
{
System.out.println(prod[i][j]);
}
}
}
}
Commentaires
Enregistrer un commentaire