Results 1 to 9 of 9
Thread: multiply two matrixes
 12062009, 06:23 PM #1Member
 Join Date
 Dec 2009
 Posts
 9
 Rep Power
 0
multiply two matrixes
Hello there,,
i wrote this programe to Add two Matrix but i didn't know how can i maltiply it pleace help me...
//This program to add two dimention
import java.util.*;
public class AddMatrex{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int[][]x=new int[2][3];
int[][]y=new int[2][3];
int [][]z=new int [2][3];
for(int i=0; i<2; i++){
for(int j=0; j<3; j++){
System.out.println("For the First Matrex row" +i+ "column" +j);
x[i][j]=scan.nextInt();
System.out.println("For the scond Matrx row" +i+ "column" +j);
y[i][j]=scan.nextInt();
z[i][j]=0;
z[i][j]= x[i][j] + y[i][j];
}
}
System.out.println("The 1st matrix");
for(int i=0; i<2; i++){
for(int j=0; j<3; j++){
System.out.print(x[i][j]+"\t");
}
System.out.println();
}
System.out.println("***************************");
System.out.println("The 2nd Matrix");
for(int i=0; i<2; i++){
for(int j=0; j<3; j++){
System.out.print(y[i][j]+"\t");
}
System.out.println();
}
System.out.println("***************************");
System.out.println("The Agging Matrix");
for(int i=0; i<2; i++){
for(int j=0; j<3; j++){
System.out.print(z[i][j]+"\t");
}
System.out.println();
}
}
}
 12062009, 06:33 PM #2Member
 Join Date
 Dec 2009
 Posts
 24
 Rep Power
 0
you need to do something like this
for(int row = 0; row<matrix1.length; row++)
{
for(int column= 0; column<matrix1[row].length; column++)
{
matrix3[row][column] = matrix1[row][column]+matrix2[row][column];
}
}
 12062009, 06:52 PM #3
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 29
You can't multiply two 2x3 matrixes.
kind regards,
Jos
 12062009, 06:59 PM #4Member
 Join Date
 Dec 2009
 Posts
 9
 Rep Power
 0
 12062009, 07:03 PM #5Member
 Join Date
 Dec 2009
 Posts
 9
 Rep Power
 0

 12062009, 07:11 PM #7Member
 Join Date
 Dec 2009
 Posts
 9
 Rep Power
 0
 12062009, 07:34 PM #8
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 29
Element P[i, j] of the product matrix A*B is the dot product of row A[i] and column C[j]. So a fragment of Java can be:
Java Code:for (int i= 0; i < A.length; i++) for (int j= 0; j < B[i].length; j++) P[i][j]= dot(A, B, i, j);
kind regards,
Jos
 12062009, 07:43 PM #9Member
 Join Date
 Dec 2009
 Posts
 9
 Rep Power
 0
Similar Threads

display column value multiply with 100
By tiiim83 in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 01152009, 04:40 AM 
How to multiply two matrices
By Java Tip in forum java.langReplies: 0Last Post: 04142008, 09:50 PM
Bookmarks