matrix multiplication in java

Solutions on MaxInterview for matrix multiplication in java by the best coders in the world

showing results for - "matrix multiplication in java"
Isabella
28 Apr 2016
1public class Matrix {
2  private double[][] multiply(double[][] matrixOne, double[][] matrixTwo) {
3            assert matrixOne[0].length == matrixTwo.length: "width of matrix one must be equal to height of matrix two";
4            double[][] product = new double[matrixOne.length][matrixTwo[0].length];
5    		//fills output matrix with 0's
6            for(short l = 0; l<matrixOne.length; l++) {
7                for(short m = 0; m<matrixTwo[0].length; m++) {
8                    product[l][m] = 0;
9                }
10            }
11    		//takes the dot product of the rows and columns and adds them to output matrix
12            for(short i = 0; i<matrixOne.length; i++) {
13                for(short j = 0; j<matrixTwo[0].length; j++) {
14                    for(short k = 0; k<matrixOne[0].length; k++) {
15                        product[i][j] += matrixOne[i][k] * matrixTwo[k][j];
16                    }
17                }
18            }
19            return product;
20        }
21}
Maxime
15 Jun 2016
1    public class MatrixMultiplicationExample{  
2    public static void main(String args[]){  
3    //creating two matrices    
4    int a[][]={{1,1,1},{2,2,2},{3,3,3}};    
5    int b[][]={{1,1,1},{2,2,2},{3,3,3}};    
6        
7    //creating another matrix to store the multiplication of two matrices    
8    int c[][]=new int[3][3];  //3 rows and 3 columns  
9        
10    //multiplying and printing multiplication of 2 matrices    
11    for(int i=0;i<3;i++){    
12    for(int j=0;j<3;j++){    
13    c[i][j]=0;      
14    for(int k=0;k<3;k++)      
15    {      
16    c[i][j]+=a[i][k]*b[k][j];      
17    }//end of k loop  
18    System.out.print(c[i][j]+" ");  //printing matrix element  
19    }//end of j loop  
20    System.out.println();//new line    
21    }    
22    }}  
Cristina
14 May 2016
1// matrix multiplication java
2public class MatrixMultiplicationJavaDemo 
3{
4   public static int[][] multiplyMatrix(int[][] matrix1, int[][] matrix2, int row, int column, int col)
5   {
6      int[][] multiply = new int[row][col];
7      for(int a = 0; a < row; a++) 
8      {
9         for(int b = 0; b < col; b++) 
10         {
11            for(int k = 0; k < column; k++) 
12            {
13               multiply[a][b] += matrix1[a][k] * matrix2[k][b];
14            }
15         }
16      }
17      return multiply;
18   }
19   public static void printMatrix(int[][] multiply) 
20   {
21      System.out.println("Multiplication of two matrices: ");
22      for(int[] row : multiply) 
23      {
24         for(int column : row) 
25         {
26            System.out.print(column + "    ");
27         }
28         System.out.println();
29      }
30   }
31   public static void main(String[] args) 
32   {
33      int row = 2, col = 3;
34      int column = 2;
35      int[][] matrixOne = {{1, 2, 3}, {4, 5, 6}};
36      int[][] matrixTwo = {{7, 8}, {9, 1}, {2, 3}};
37      int[][] product = multiplyMatrix(matrixOne, matrixTwo, row, col, column);
38      printMatrix(product);
39   }
40}
queries leading to this page
matrix multiplication in java using functionmatrix multiplication java orcalemultiply matrix java with single arraymatrices of different order multiplication javaprogram to perform matrix multiplication in javajava block matrix multiplicationmatrix library in javamultiplication of two matrix javamultiply matrices code javamultiply matrix java with a methods 22n dimensional 22 matrix multiplication javajava program multiply two matrices3 2a3 matrix multiplication in javahow to do matrix multiplication in 2d array in javamatrix multiplication javamatrix multiplication program in javamultiply polynomials java2x2 4 elemnts matrix multiplication in java2 matrix multiplication in javajava method for matrix multiplicationn dimensional matrix multiplication java3 2a3 matrix multiplication javamatrix multiplication java 2dmutliply two matrcies in javamatrix addition javamultiplication of to matrixes javahow to multiply two matrices in javamultiply two given matrices in javaperforming matrix multiplication in javamatrix multiplication injvawrite a program to multiply two matrices in java 2 2a2matrix multiplicaiotn javamultiply matrix in javva3x3 matrix multiplication javatwo matrix multiplication in javajava function multiply two matricesmultiply 2d array javamultiply two matrix in java figurejava program to mulitpy 2 matricesmatrix multiplication in java cdeprogram to multiply to arrays in java2d array multiplication in javajava matrix multiplication built in functionmultiplication of 2d matrix javajava function to multiply two matricesjava program to perform matrix multiplicationmultiplication of array in javamultiplication of matrices in java programjava matrix multiplication javawrite a function to multiply two matrices of any size javahow to multiply matrix in javamultiplication of matrices in javajava 2d matrix multiplicationjava multiply two matricesmultiplication of two matrix in javahow to matrix multiplication in javproduct of two matrices in javamultithreading matrix multiplication javamatrix mulitplication in javamultiply 1d matrix javamatrix multiplication using multidimensional array in javahow to multiply matrices javamatrix multiplication in java from usermultiply matrices javawrite a code in java to find the calculation time of multiplication of two 2x2 matrices using regular method and take input from usermultiplication of 2 arrays in javamultiplication of matrices javamultiplication of two matrices in java2 write a java program to multiply two given matrices using 2d arraymultiplicaion of matrices in javamultiplying matrices javajava matrix multiplicationhow to multiply matrixes in javafastest way to multiply matrices javacalculate matrix multiplication javamultiplying matrix in java programwrite a java program to multiply two matrices multiply matrix vector javajava program for matrix multiplication using arrayjava p to multiply two matrices of any size addition of two matrix in javafastes way to multiply matrices javatwo matrices of different order multiplication in javamultpily matrix in javamultiplicar matrices en javawrite a program to multiply 2 matrices javamatrix multiplication in multithreading javamatrix multiplication java programwrite a program in java to find axb where a is a matrix of 3x3 and b is a matrix of 2x3 how to multiply a matrix by one number javawhy use matrix multiplication in javamultiply two matrix in java programmultiply two matrices in javawrite a program to multiply two matrices in java 2 2a2 and take input from userjava multiplicar matricesjava multiply matrix with listjava matrix multiply 29 java program to multiply two matricesmultiply matrix method javajava program for multiplying two given matricesmultiply 2d array in java2d matrix multiplication in javamultipliaction of two matrices in java2x2 matrix multiplication in javamatrix multiplication in java using methodsjava program for matrix multiplicationjava program multiply 3 by 3 2a3 matricesjava multiply matrix with itselfmatrix multiply javamultiplication matrix in javajava matrix multiplication methodptroduct of two matrices javamultiply matirx javajava program to multiply two matricesmatrix multiplication in javamatrices multiplication javamultiply array javamultiplication of matrix in javamultiply 2 matrix in javamultidimensional array multiplication in javajava multiply matrix with vectormatrix product javawrite a program to multiply two matrices in javajava multiplying matricesjava matrix multiplication libraryhow to multiply matrices in javahow to do matrix multiplication in javahow to multiply a matrix for a value in jvaprogram to multiply two arrays in javahow to multiply 2 matrices in javamatrix multiplication of different order in javacode to multiply matrices javamatrix product in javawrite a code in java to find the calculation time of multiplication of two 2x2 matrices using regular methodhow to multiply matrixs javamultiply the matrices javamultiplication code of two matrices in javaprogram to multiply two matrices in javamatrices javamultiplicate a matrix by a number javamultiply matrix in javasimple matrix ca c2 b4lass in java with matrix multiplicationmutiply matrices javamatrix multiplication code in javamultiply matrix javajava multiply matricesmultiplication of two matrix program in javajava program for multiplication of two matricesjava array multiplication java multiply matrixmultiplication of arrays in javajava program for multiplying two matricesmultiplication of matrix javamultiplication of a matrix in javamultiply the matrices in javamatrix multiplaction javamultiply 2 matrices javamultiply of two matrix in javacode for 2 2a 2 matrix multiplication in java program to multiply a square matrix by a column matrix javamatrix multiplication in java