TRENDING NEWS

POPULAR NEWS

Java Program To Multiply Matrices Using Threads

Give me the code for multiplying two matrices in core java using Exception handling.?

And what exactly would you give us in return?

// This is sample program for matrix multiplication// The complexity of the algorithm is O(n^3)package com.sanfoundry.numerical;import java.util.Scanner;public class MatixMultiplication{public static void main(String args[]){int n;Scanner input = new Scanner(System Resources and Information.);System.out.println("Enter the base of squared matrices");n = input.nextInt();int[][] a = new int[n][n];int[][] b = new int[n][n];int[][] c = new int[n][n];System.out.println("Enter the elements of 1st martix row wise \n");for (int i = 0; i < n; i++){for (int j = 0; j < n; j++){a[i][j] = input.nextInt();}}System.out.println("Enter the elements of 2nd martix row wise \n");for (int i = 0; i < n; i++){for (int j = 0; j < n; j++){b[i][j] = input.nextInt();}}System.out.println("Multiplying the matrices...");for (int i = 0; i < n; i++){for (int j = 0; j < n; j++){for (int k = 0; k < n; k++){c[i][j] = c[i][j] + a[i][k] * b[k][j];}}}System.out.println("The product is:");for (int i = 0; i < n; i++){for (int j = 0; j < n; j++){System.out.print(c[i][j] + " ");}System.out.println();}input.close();}}Output:Enter the base of squared matrices:3Enter the elements of 1st martix row wise:1 2 34 5 67 8 9Enter the elements of 2nd martix row wise:2 3 45 6 78 9 1Multiplying the matrices...The product is:36 42 2181 96 57126 150 93to learn more in a effective manner click here

Write a program in Java to multiply two matrices.?

Here is you answer



class MatrixMultiply{
public static void main(String[] args) {
int array[][] = {{5,6,7},{4,8,9}};
int array1[][] = {{6,4},{5,7},{1,1}};
int array2[][] = new int[3][3];
int x= array.length;
System.out.println("Matrix 1 : ");
for(int i = 0; i < x; i++) {
for(int j = 0; j <= x; j++) {
System.out.print(" "+ array[i][j]);
}
System.out.println();
}
int y= array1.length;
System.out.println("Matrix 2 : ");
for(int i = 0; i < y; i++) {
for(int j = 0; j < y-1; j++) {
System.out.print(" "+array1[i][j]);
}
System.out.println();
}

for(int i = 0; i < x; i++) {
for(int j = 0; j < y-1; j++) {
for(int k = 0; k < y; k++){

array2[i][j] += array[i][k]*array1[k][j];
}
}
}
System.out.println("Multiply of both matrix : ");
for(int i = 0; i < x; i++) {
for(int j = 0; j < y-1; j++) {
System.out.print(" "+array2[i][j]);
}
System.out.println();
}
}
}

C program will display the product of any Two Matrices using pointers. To multiply (find product) any two matrices, the number of columns of the first matrix must be equal to the number of rows of the the second matrix.#include int main(){ int matrix1[20][20],matrix2[20][20],product[20][20]; int *p1,*p2,*prod,m,n,p,q,d,e,f; p1=matrix1; p2=matrix2; prod=product; clrscr(); printf("\nEnter the size (no of rows and columns) for 1st matrix :\n"); scanf("%d%d",&m,&n); printf("\nEnter the size (no of rows and columns) for 2nd matrix :\n"); scanf("%d%d",&p,&q); if(n==p) { printf("\n Enter the 1st matrix elements : \n"); for(d=1;d<=m;++d) for(e=1;e<=n;++e) scanf("%d",p1+d*20+e); printf("\n Enter the 2nd matrix elements : \n\n"); for(d=1;d<=p;++d) for(e=1;e<=q;++e) scanf("%d",p2+d*20+e); printf("\nThe given 1st Matrix is . . . \n\n"); for(d=1;d<=m;++d){ for(e=1;e<=n;++e) printf("\t %d", *(p2+d*20+e)); printf("\n\n"); } printf("\nThe given 2nd Matrix is . . . \n\n"); for(d=1;d<=p;++d){ for(e=1;e<=q;++e) printf("\t %d", *(p1+d*20+e)); printf("\n\n"); } for(d=1;d<=m;++d) for(e=1;e<=q;++e) *(prod+d*20+e) = 0; for(d=1;d<=m;++d) for(e=1;e<=q;++e) for(f=1;f<=n;++f) *(prod+d*20+e) += *(p1+d*20+f) * *(p2+f*20+e); printf("\n\nThe Product of two matrices using Pointer is . . . \n\n"); for(d=1;d<=m;++d){ for(e=1;e<=q;++e) printf("\t %d", *(prod+d*20+e)); printf("\n\n"); } } else printf("\nThe Matrix sizes are not compatible for multiplication !!"); getch(); return 0; }If you want help in programming, our experts will provide best services at Best & Affordable Computer Science Homework Help

Multiply two this matrices in C++ :[1*5]&[5*3]?

include
#include
#include
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,k;
int m,n,o,p;
cout<<"Enter The Rows And Cloumns Of The First Matrix:";
cin>>m>>n;
cout<<"\nEnter Elements Of The First Matrix:\n";
for(i=0;i{
for(j=0;j< n;j++)
{
cin>>a[i][j];
}
}
cout<<"Enter The Rows And Cloumns Of The Second Matrix:";
cin>>o>>p;
cout<<"\nEnter Elements Of The Second Matrix:\n";
for(i=0;i{
for(j=0;j{
cin>>b[i][j];
}
}
cout<<"The First Matrix Is:\n";
for(i=0;i{
for(j=0;j{
cout<}
cout<<"\n";
}
cout<<"The Second Matrix Is:\n";
for(i=0;i{
for(j=0;j{
cout<}
cout<<"\n";
}
if(n!=o)
{
cout<<"Aborting!!!!!!/nMultiplication Of The Above Matrices Not Possible.";
}
else
{
for(i=0;i< m;i++)
{
for(j=0;j< p;j++)
{
c[i][j] = 0;
for(k=0;k< o;k++)
{
c[i][j] = c[i][j] + a[i][k] * b[k][j];
}
}
}
cout<<"\nMultiplication Of The Above Two Matrices Is:\n\n";
for(i=0;i< m;i++)
{
for(j=0;j< p;j++)
{
cout<}
cout<<"\n";
}
}
getch();
}

Java using matrices problem?

what is wrong with my code?

public class Exer11{
public static void main(String[] args) {
int i, x = 5, y = 6;
int arr[][] = new int arr[x][y];
if(arr[x][y] == arr[y][x]) {
System.out.println("Symmetric");
}
if(arr[x][y] == 0)
if(x!=y)
System.out.println("Diagonal");
if(x System.out.println("Upper triangular");
if(x>y)
System.out.println("Lower Triangular");
}
}
}

i should read an NxN matrix into a two dimensional array and determine whether where they land.

Java Programming Multiplication program?

I am trying to write a Java Program that teaches multiplication by displaying a multiplication problem (i.e. How much is 6 times 7 with 6 and 7 being the random number). Then the person is supposed to guess/answer the problem. If they get it right then a message is displayed "Very Good" or wrong "No. Please try again." Anyway, my biggest problem is figuring out how to write the program to display the random numbers and then multiply them. The rest of it I can figure out but I cannot even figure out how to "print" the random number that was picked.

Help is appreciated.

Matrix multiplication are used for many reasons in programming.For example:-1> Given a directed graph [math]G =(V,A)[/math] in the form of adjacency matrix M. Now, you are asked to count all paths of length say k. How to find it? [math] M^k [/math]would hold your answer.2> To solve Linear equations, say you are given,[math]x + y + z = 6 [/math][math] 2y+ 5z = -42 [/math][math]2x + 5y -z = 27[/math]We, can represent this set of equations like this [math]AX = B.[/math]To solve for X, we can simplify [math]AX = B[/math] , to [math]X = A^{-1} . B[/math]You can now compute matrix multiplication of [math]A^{-1} . B[/math] to find [math]X[/math].3> It also used a lot in game theory. For a finite and solvable game where each player knows each other set of moves, you can represent these moves in terms of matrix [math]M [/math]and the value of each matrix cell would be the payoff (gain/loss). Now, say if you want to find what would be the best consecutive 3 moves, you can do [math]M^3.[/math]4> Matrix multiplication is also very helpful for image rendering. Think about how a light should illuminate an object where you know the co-ordinates of the light and the object and the angle of incidence of light.5> Finding the Hyperbolicity of a graph. Sage Reference Manual v7.6: Graph Theory .I currently can’t think of more applications of Matrix multiplication but you get the idea. :)Image source: Solving Systems of Linear Equations Using Matrices

Multiplication matrices method in Java?

I am trying to multiply two vectors ( a= 1x2 , b=transpose(a) (so b= 2x1))

Here is what I have....

public double[][] multiply(double[][] a, double[][] b) {
double[][] new = new double[a[0].length][b.length];
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < b[0].length; j++) {
for (int k = 0; k < a[0].length; k++) {
new[i][j] += a[i][k] * b[k][j];
}
}
}

return new;
}
}

This is what it prints out.....

The a 0 0: 1.1552885629499996
The a 0 1: -0.683638613525
The b 0 0: 1.1552885629499996
The b 1 0: -0.683638613525
The multi 0 0: 1.8020534175854594
The multi 0 1: 0.0
The multi 1 0: 0.0
The multi 1 1: 0.0

So, in the (0,0) is a number, but in (0,1), (1,0), (1,1) are all 0.0?
And the multi is print out a 2x2 like it should... Iam not sure why its filling with 0 after the first one

Multiplying two hexadecimal numbers is the same as multiplying any two decimal numbers. Hexadecimal is just another way of representing numbers, the actual number is the same. For example:int a=0x7B; // in decimal: 123int b=0x6E; // in decimal: 110System.out.println(a*b);output: 13530The output will be the product of a and b i.e. 123* 110. You just have to see that the hexadecimal number is valid. A valid hexadecimal number starts with ox in java (don't know if it is same everywhere else)

TRENDING NEWS