Matrix multiplication using arrays

0 votes

Utilizing multidimensional arrays, I'm attempting to create a straightforward matrix multiplication approach ([2][2]). Being rather new at this, I'm unable to identify my mistakes. Please let me know what it is if you can; I'd really appreciate it. Since I'm basically doing this to learn how it works, I'd prefer not to use libraries or anything similar. 

My variable declaration is as follows:

Double[][] A={{4.00,3.00},{2.00,1.00}}; 
Double[][] B={{-0.500,1.500},{1.000,-2.0000}};

A*B should return the identity matrix. But it won't work. This is the code:

public static Double[][] multiplicar(Double[][] A, Double[][] B){
    Double[][] C= new Double[2][2];
    int i,j;

    for(i=0;i<2;i++) {
        for(j=0;j<2;j++){
            C[i][j]=0.00000;
        }
    } 

    for(i=0;i<2;i++){
        for(j=0;j<2;j++)
            C[i][j]+=(A[i][j]*B[j][i]);
    }
    return C;
}
Aug 5, 2022 in Java by krishna
• 2,820 points
381 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Java

0 votes
2 answers

How do I get the current date and time using Java?

If you require a time stamp in ...READ MORE

answered Aug 23, 2019 in Java by Sirajul
• 59,230 points
2,299 views
0 votes
2 answers

How can I create File and write data in it using Java?

import java.io.BufferedWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public class WriteFiles{ ...READ MORE

answered Jul 26, 2018 in Java by samarth295
• 2,220 points
2,511 views
0 votes
3 answers

How to read input from Console using Scanner Class?

A simple example: import java.util.Scanner; public class Expl { ...READ MORE

answered Aug 1, 2018 in Java by samarth295
• 2,220 points
4,491 views
0 votes
2 answers

How to concatenate two arrays in Java?

public <T> T[] concatenate(T[] a, T[] b) ...READ MORE

answered Jul 19, 2018 in Java by Sushmita
• 6,910 points
2,397 views
0 votes
1 answer

How can I create an executable JAR with dependencies using Maven?

<build> <plugins> <plugin> ...READ MORE

answered Apr 26, 2018 in Java by sophia
• 1,400 points
975 views
0 votes
1 answer

How can I read a large text file line by line using Java?

// Open the file FileInputStream file = new ...READ MORE

answered May 2, 2018 in Java by Parth
• 4,630 points
679 views
0 votes
0 answers

Multidimensional Arrays lengths in Java

How can I determine the lengths of ...READ MORE

Aug 8, 2022 in Java by krishna
• 2,820 points
207 views
0 votes
0 answers

Arrays.fill with multidimensional array in Java

Without using a loop, how can I ...READ MORE

Nov 16, 2022 in Java by Ashwini
• 5,430 points
413 views
0 votes
2 answers

How an object array can be converted to string array in java?

System.arraycopy is the most efficient way, but ...READ MORE

answered Aug 8, 2018 in Java by Sushmita
• 6,910 points
4,691 views
0 votes
2 answers

How does random shuffling of an array

Here is a simple way using an ArrayList: List<Integer> ...READ MORE

answered Nov 2, 2018 in Java by Sushmita
• 6,910 points
630 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP