I am a java beginner and I was given this task to do.. to create a class which given 2 matrices,and these bein of the correct dimensions, will produce a third matrix by multiplying both. There is the need of a class Matrix which contains the following methods :
public Matrix multiply (Matrix multiplicand, Matrix multiplier); and
public void display();
The display() method will output a matrix upon the console, columns should be tabbed and
rows printed on a new line e.g.
20 6 112
1 -761 12
85 30 -65
The matrix may have a any number of columns or rows. Your Matrix class must be flexible enough to support this. Generate a program which randomly creates matrices and multiplies them, always displaying each matrix (the multiplicand, multiplier and the result..)
Can please some1 help me in dealing with this task? Thanks very much
12 9732
I am a java beginner and I was given this task to do.. to create a class which given 2 matrices,and these bein of the correct dimensions, will produce a third matrix by multiplying both. There is the need of a class Matrix which contains the following methods :
public Matrix multiply (Matrix multiplicand, Matrix multiplier); and
public void display();
The display() method will output a matrix upon the console, columns should be tabbed and
rows printed on a new line e.g.
20 6 112
1 -761 12
85 30 -65
The matrix may have a any number of columns or rows. Your Matrix class must be flexible enough to support this. Generate a program which randomly creates matrices and multiplies them, always displaying each matrix (the multiplicand, multiplier and the result..)
Can please some1 help me in dealing with this task? Thanks very much
And what have you done so far?
I am a java beginner and I was given this task to do.. to create a class which given 2 matrices,and these bein of the correct dimensions, will produce a third matrix by multiplying both. There is the need of a class Matrix which contains the following methods :
public Matrix multiply (Matrix multiplicand, Matrix multiplier); and
public void display();
The display() method will output a matrix upon the console, columns should be tabbed and
rows printed on a new line e.g.
20 6 112
1 -761 12
85 30 -65
The matrix may have a any number of columns or rows. Your Matrix class must be flexible enough to support this. Generate a program which randomly creates matrices and multiplies them, always displaying each matrix (the multiplicand, multiplier and the result..)
Can please some1 help me in dealing with this task? Thanks very much
So for matrixes A and B with n rows, m columns and m rows, p columns respectively,
what would be the size of matrix C == A*B?
How would you test whether or not A and B have the correct sizes? and how
do you calculate the dot product of row i of matrix A times column j of matrix B?
What have you calculated then? Have you thought about these sub-problems?
kind regards,
Jos
what i know is that i need to build a matrix with 2 arrays [] []. The length of these arrays need to be randomly generated. Also the first element in the first array needs to be multiplied by the first element in the other array.
I dont know how to do this in java.. also i dont know how to randomly generate the length of an array.
Thanks
Regards
Christine
I dont know how to do this in java.. also i dont know how to randomly generate the length of an array.
You do know how to program using the Java programming language don't you?
kind regards,
Jos
what i know is that i need to build a matrix with 2 arrays [] []. The length of these arrays need to be randomly generated. Also the first element in the first array needs to be multiplied by the first element in the other array.
I dont know how to do this in java.. also i dont know how to randomly generate the length of an array.
Thanks
Regards
Christine
Before you start thinking about how to do stuff in Java, first get a Math tutorial and make sure you know how to multiply matrices manually. Note down all the special cases e.t.c
Then read a Java arrays tutorial. After that all you need to do is read the API for the java.util.Random class and you're done.
I guess you realize that the keyword in all that is read.
You can always post back here at any time that you get stuck with any of the above.
Hi,
To find the Product of two Matrices, First we've to verify the matrix sizes, for this we've a Condition like No.of Columns of First Matrix (A) should be equla to No.of Rows in Second Matrix (B) then in the resultant matrix (C), No.of Rows should be equal to the no.of Rows in First Matrix(A) and the no.of Columns of Resultant Matrix (C) should be equal to the no.of Columns of Second Matrix (B).
For example, A is a Matrix with the size of 3x2, and B is a Matrix with the size of 2x4 then the Resultant Matrix (C) size should be 3x4 (No.of Rows in A x No.of Columns in B) as These matrices satisfy the condition as no.of Columns of A are equal to No.of Rows in B)
so go ahead,
Cheers,
Sateesh.
I' ve done the following code.. but I dont know how to randomly generate the numbers and the length of the arrays.. The length of the arrays need to have certain restriction that the first matrix must have number of columns equal to the number of rows of the second matrix.
public class Matrix {
// the dimensions for the matrix
// Matrix dimensions
int nRowsMatrixA = 2; // number of rows for matrix A
int nColsMatrixA = 3; // number of columns for matrix A
int nRowsMatrixB = 3; // number of rows for matrix B
int nColsMatrixB = 2; // number of columns for matrix B
int nRowsMatrixC = 2; // number of rows for matrix C
int nColsMatrixC = 2; // number of columns for matrix C
double [][] matrixA = new double [nRowsMatrixA][nColsMatrixA];
double [][] matrixB = new double [nRowsMatrixA][nColsMatrixB];
double [][] matrixC = new double [nRowsMatrixC][nRowsMatrixC];
Random rand = new Random();
matrixA [0][0] = rand.nextInt(20);
public Matrix multiply (Matrix multiplicand, Matrix multiplier) {
}
}
I' ve done the following code.. but I dont know how to randomly generate the numbers and the length of the arrays..
For random numbers, use java.util.Random.
About the issue of creating compatible Matrixes, you'll have to either read the lengths from the first Matrix while creating the second one or save them before creating the first Matrix and reuse them in the second one.
Greetings,
Nepomuk
well i jst tried 2 get this code done fr my college tutorials!....
multiplication of matrices wid unequal orders!
works great....jst get thru d logic done!
lol...its huge...ignore d strngs fr the user plz! :P -
#include<stdio.h>
-
void main()
-
{
-
int i,j,k,x=0,ai,aj,bi,bj,a[10][10],b[10][10],c[10][10];
-
wrong:
-
printf("enter in the order(ixj) of matrix A\n");
-
scanf("%d",&ai);
-
scanf("%d",&aj);
-
printf("\nnow the order(ixj) of matrix B\n");
-
scanf("%d",&bi);
-
scanf("%d",&bj);
-
printf("\nOrder of matrix A = (%dx%d)\n",ai,aj); //display orders of
-
printf("Order of matrix B = (%dx%d)\n\n",bi,bj); //of A n B!
-
-
if(aj!=bi)
-
{
-
printf("The resultant product matrix wont exist as Ai and Bj aren't equal!\n");
-
printf("\n\nEnter in the orders again!\n");
-
goto wrong;
-
}
-
-
printf("Enter the matrix 'A'(row by row)\n\n"); //input fr matrix A!
-
for(i=0;i<ai;i++)
-
{
-
printf("Row%d\n",i+1);
-
for(j=0;j<aj;j++)
-
scanf("%d",&a[i][j]);
-
}
-
-
-
printf("\nEnter the matrix 'B'(row by row)\n\n"); //input fr matrix B!
-
for(i=0;i<bi;i++)
-
{
-
printf("Row%d\n",i+1);
-
for(j=0;j<bj;j++)
-
scanf("%d",&b[i][j]);
-
}
-
-
printf("\n\n\nthe matrices of multiplication are!\n\nA:");
-
for(i=0;i<ai;i++) //display A matrix!
-
{
-
printf("\t");
-
for(j=0;j<aj;j++)
-
printf("%d\t",a[i][j]);
-
printf("\n\n");
-
}
-
-
printf("\n\nB:"); //display B matrix!
-
for(i=0;i<bi;i++)
-
{
-
printf("\t");
-
for(j=0;j<bj;j++)
-
printf("%d\t",b[i][j]);
-
printf("\n\n");
-
}
-
-
-
for(i=0;i<ai;i++) //multiplicatn(main logic)
-
{
-
for(j=0;j<bj;j++)
-
{
-
x=0;
-
for(k=0;k<aj;k++)
-
x=x+a[i][k]*b[k][j];
-
c[i][j]=x;
-
}
-
}
-
-
-
-
printf("\n\nThe multiplication of the above matrices A & B....C:\n\nA x B = ");
-
for(i=0;i<ai;i++) //display d product result!
-
{
-
printf("\t");
-
for(j=0;j<bj;j++)
-
printf("%d\t",c[i][j]);
-
printf("\n\n\t");
-
}
-
-
}
-
-
#include<stdio.h>
-
void main()
-
{
-
Oh dear; this is a Java forum and your source code isn't valid C or C++ either.
kind regards,
Jos
i would like to know if it is possible to find a scalar r if we multiplythe matrixesM and N such that MN=rN
M= 3 -0.50 0.50 and matrix N= 6.75
0 6.50 -8 13.5
0 4 -5. 6.750
PLEASE HELP
i would like to know if it is possible to find a scalar r if we multiplythe matrixesM and N such that MN=rN
M= 3 -0.50 0.50 and matrix N= 6.75
0 6.50 -8 13.5
0 4 -5. 6.750
PLEASE HELP
Read up on 'eigen values' and 'eigen vectors' here. btw, you should have
started your own thread for this; hijacking is considered impolite and not done.
kind regards,
Jos
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
11 posts
views
Thread by Michael Bader |
last post: by
|
3 posts
views
Thread by robix |
last post: by
|
14 posts
views
Thread by amitnanda |
last post: by
| | |
7 posts
views
Thread by VijaKhara |
last post: by
|
6 posts
views
Thread by amitsoni.1984 |
last post: by
|
3 posts
views
Thread by crazygrey |
last post: by
| | | | | | | | | | | | |