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 9882
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 subproblems?
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
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Michael Bader 
last post by:
Hi,
I'm currently working on a matrix multiplication code (matrix times
matrix), and have come along some interesting/confusing results
concerning the running time of the (apparently) same...

by: robix 
last post by:
Hi again. I'm now asking your help because of a smal problem i'm getting
with my multiplication matrix code.
I'll try to give you as many details as possible.
My matrix structure:
typedef...

by: amitnanda 
last post by:
Hi Guys,
I have a matrix multiplication program in C that multiplies two
matrices.
When their size is 3*3 or 800*800, the program runs fine. But above
that size, I get a "segmentation fault"....

by: lituncse 
last post by:
dear friends,
i have come across a problem which is difficult to solve for me.it's about starssen's matrix multiplication.in general matrix multiplication we need 8 multiplications and 4 additions...

by: emaghero 
last post by:
Does anybody know an algorithm for the fast multiplication of three nxn symmetric matrices?
I have an algorithm, which I'm not too pleased with, that does the job.
Does anybody know a faster...

by: VijaKhara 
last post by:
Hi all,
Is there any method which can implememt the matrix multiplication
faster than using the formula as we often do by hand?
I am writing the following code and my matrice: one is 3x40000 and...

by: amitsoni.1984 
last post by:
Hi,
Is there any direct function for matrix multiplication in Python or
any of its packages? or do we have to multiply element by element?
Thank you,
Amit

by: crazygrey 
last post by:
Hello, I'm a newbie to C++ so excuse me if my question was trivial but
it is important to me.
I'm implementing a simple code to find the forward kinematics of a
robot:
#include "stdafx.h"...

by: Sozos 
last post by:
Hi guys. I have a problem with writing the base case for the following matrix multiplication function I have implemented. Please help.
#define index(i,j,power) (((i)<<(power))+(j))
void...

by: joegao1 
last post by:
can some one give me a hint?
I want to program the code for matrix multiplication with as less arithmetical / multiplication operations as possible.
my task is to calculate the matrix...

by: VivesProcSPL 
last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many Englishlike terms and syntax in an effort to make it easy to learn, particularly for...

by: isladogs 
last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
For other local times, please check World Time Buddy
In...

by: jianzs 
last post by:
Introduction
Cloudnative applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...

by: abbasky 
last post by:
### Vandf component communication method one: data sharing
Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...

by: jimatqsi 
last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...

by: isladogs 
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...

by: fareedcanada 
last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...

by: egorbl4 
last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это
Что это? Что мне с этим делать?
...

by: davi5007 
last post by:
Hi,
Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
 