code for multiplication of matrix in java using methods

Ads
 

code for multiplication of matrix in java using methods

code for multiplication of matrix in java using methods

View Answers

April 20, 2011 at 10:55 AM

   import java.util.*;
    class MatrixMultiplication{

        public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int[][] A = new int[3][3];
    int[][] B = new int[3][3];
    int[][] C = new int[3][3];
    System.out.println("Enter elements for matrix A : ");
    for (int i=0 ; i < A.length ; i++)
    for  (int j=0 ; j < A[i].length ; j++){
    A[i][j] = input.nextInt();
    }
    System.out.println("Enter elements for matrix B : ");
    for (int i=0 ; i < B.length ; i++)
    for  (int j=0 ; j < B[i].length ; j++){
    B[i][j] = input.nextInt();
    }
    System.out.println("Matrix A: ");
            for (int i=0 ; i < A.length ; i++){
                System.out.println();
                for  (int j=0 ; j < A[i].length ; j++){
                    System.out.print(A[i][j]+" ");
                      }
            }
    System.out.println();
    System.out.println();
    System.out.println("Matrix B: ");
            for (int i=0 ; i < B.length ; i++){    
                System.out.println();
                for  (int j=0 ; j < B[i].length ; j++){
                    System.out.print(B[i][j]+" ");
                      }
            }
    System.out.println();
    System.out.println();
    System.out.println("Result is: ");
    System.out.println();

    for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
    for(int k=0;k<3;k++){
    C[i][j]+=A[i][k]*B[k][j];
    }
    }
    }
    for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
    System.out.print(+C[i][j]+" ");
    }
    System.out.println();
    } 
    }
    }

October 28, 2011 at 10:12 PM

for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ for(int k=0;k<3;k++){ C[i][j]+=A[i][k]*B[k][j]; } } } It is a super formula for Multiplication of matrix

I also did this by using the following code

for(int i=1,c=1,d=1,p=1,o=1;o<=3;o++,++c,++p){ for(int j=1,q=1;j<=3;j++,++q){
z[p][q]=x[c][d]y[i][j]+x[c][d+1]y[i+1][j]+x[c][d+2]*y[i+2][j]; } }

the codeing which I done seems to be more complicated but I did with only two "for loops"

Ads









Related Tutorials/Questions & Answers:
code for multiplication of matrix in java using methods
code for multiplication of matrix in java using methods  code for multiplication of matrix in java using methods
Parallel multiplication matrix in java
Parallel multiplication matrix in java  hello dear I need parallel multiply matrix in java algorithm to account speed up and efficiency great wishes
Advertisements
Matrix Multiplication in Java
Matrix Multiplication in Java In this Java tutorial we will demonstrate you 'Matrix Multiplication in Java' with the help of a simple example from which you can easily learn how to write a matrix multiplication program in Java
determinant of n*n matrix using java code
determinant of n*n matrix using java code  Here is my code... Scanner(System.in); System.out.println("enter dimension of matrix"); N...]; } System.out.println("enter the elements of matrix"); for(int i=0;i<N;i
parallel dense matrix multiplication
using dense parallel matrix multiplication. I request you to kindly provide me a code for Parallel Matrix multiplication on distributed systems using Java...parallel dense matrix multiplication  hi friends, i am a final year
Matrix Addition using RMI in Java
Matrix Addition using RMI in Java  Source Code for Matrix Addition using RMI in Java
Matrix multiplication in java
Matrix multiplication in java In this section we will learn about multiplication of two matrices. In java this is a simple program to multiply two matrices... two-dimensional array. Here we are going to develop a Java code for matrices
Multiplication of two polynomials using linked list in java
Multiplication of two polynomials using linked list in java  I am doing a program "Multiplication of two polynomials using linked list in java...; Node q = front; //insert in front if exponent is higher
java code using swings
java code using swings  code that should be able to enter data of student details using all swings into the access database using jdbc connectivity
Display tow dimensional array by matrix form using one for loop in java
Display tow dimensional array by matrix form using one for loop in java  Display tow dimensional array by matrix form using one for loop in java
code for a simple java program which performs basic arithmetic operation addition,subtraction,multiplication,division........
code for a simple java program which performs basic arithmetic operation addition,subtraction,multiplication,division........  code for a simple java...,multiplication,division
java code using while loop
java code using while loop  
java code for PartialSearch using Map????
java code for PartialSearch using Map????  java code for Partial Search using Map
java program_big digits multiplication..
java program_big digits multiplication..  i want program about big digits multiplication program using java..plz tel me answer
core java ,io operation,calling methods using switch cases
core java ,io operation,calling methods using switch cases  How to create a dictionary program,providing user inputs using io operations with switch cases and providing different options for searching,editing,storing meanings
parsing xml file using java code
parsing xml file using java code  parsing a xml file using java code
An application using swings and vector methods
An application using swings and vector methods   Hi, I want an application in Java swings which uses good selection of Vectors methods
multiplication algorithms in java divide and conquer
multiplication algorithms in java divide and conquer  I need multiplication algorithms in java divide and conquer ask from user input two numbers in binary then the program multiply two number use multiplication algorithm in java
multiplication algorithms in java divide and conquer
multiplication algorithms in java divide and conquer  I need multiplication algorithms in java divide and conquer ask from user input two numbers in binary then the program multiply two number use multiplication algorithm in java
multiplication algorithms in java divide and conquer
multiplication algorithms in java divide and conquer  I need multiplication algorithms in java divide and conquer ask from user input two numbers in binary then the program multiply two number use multiplication algorithm in java
Reading RDF file using Java code in Eclipse
Reading RDF file using Java code in Eclipse  Could you please tel me what this statement means - Model model = ModelFactory.createDefaultModel
java string multiplication
java string multiplication  Is there any simple method of string multiplication in java ..?   public class StringMultiplication { public static void main(String[] args) { String number1 = "17"; String number2
java code using combobox,radiobutton,checkbox
java code using combobox,radiobutton,checkbox  hi, send me java code for entering student details into ms access database, the code should includes combo box,radiobutton and checkboxes pl send as early as possible
View source code of a html page using java ..
View source code of a html page using java ..  I could find the html source code of a web page using the following program, http://download.oracle.com/javase/1.4.2/docs/api/java/net/URLConnection.html i could get the html code
Java methods
Java methods  What are the differences between == and .equals
java plugin code for nutch using filter indexer
java plugin code for nutch using filter indexer  hello: i want... in the doc.add(name,value) . I don't know what is the error in it. Tthis is the code... = conf; } } I think that the error is in using parsedData but I don't know what I
multiplication
multiplication  multiplication of two number numbers entered by user minimum 100digits using GUI   Java Multiplication of two 100 digits number import java.awt.*; import java.math.*; import javax.swing.*; import
multiplication
multiplication  multiplication of two number numbers entered by user minimum 100digits using GUI   Java Multiplication of two 100 digits number import java.awt.*; import java.math.*; import javax.swing.*; import
java source code to send group mails using struts2
java source code to send group mails using struts2  code to send group mails using struts2
java source code to create mail server using struts2
java source code to create mail server using struts2  java source code to create mail server using struts2
download xml file from website using java code
download xml file from website using java code  how to download xml file from website using java code

Ads