Results 1 to 9 of 9
Thread: multiply two matrixes
- 12-06-2009, 05:23 PM #1
Member
- 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();
}
}
}
- 12-06-2009, 05:33 PM #2
Member
- 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];
}
}
- 12-06-2009, 05:52 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
You can't multiply two 2x3 matrixes.
kind regards,
Jos
- 12-06-2009, 05:59 PM #4
Member
- Join Date
- Dec 2009
- Posts
- 9
- Rep Power
- 0
- 12-06-2009, 06:03 PM #5
Member
- Join Date
- Dec 2009
- Posts
- 9
- Rep Power
- 0
-
- 12-06-2009, 06:11 PM #7
Member
- Join Date
- Dec 2009
- Posts
- 9
- Rep Power
- 0
- 12-06-2009, 06:34 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
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:
Now all you have to do it implement the dot( ... ) method.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
- 12-06-2009, 06:43 PM #9
Member
- 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: 01-15-2009, 03:40 AM -
How to multiply two matrices
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:50 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks