# Another question about multiplying two-dimensional arrays(matrices)

Page 1 of 1

## 4 Replies - 7711 Views - Last Post: 14 March 2008 - 09:48 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=46180&amp;s=45830850e5b2ef87b4ddafd66c1db28f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 dspivey5257

Reputation: 0
• Posts: 6
• Joined: 09-March 08

# Another question about multiplying two-dimensional arrays(matrices)

Posted 13 March 2008 - 07:42 PM

I have a question concerning multiplying two-dimensional arrays having different dimensions. Lets say you have the two following matrices:

int[][] matrix1 = new int[6][4];
| int[][] matrix2 = new int[4][5];
|
| They would look like below:
|
| matrix 1:
| 0 1 2 3
| 0
| 1
| 2
| 3
| 4
| 5
|
|
| matrix 2
| 0 1 2 3 4
| 0
| 1
| 2
| 3

I understand that the number of columns in matrix one must match the number of rows in matrix 2 in order to multiply them. My question is on matrix one when you get to row 4 you won't have matches in matrix 2 and when you get to column 5 in matrix 2 you won't have matches in matrix 1. How do you multiply them when there are not matches? Does it take zero and multiply it by the match? I'm so confused, all my instructors says is that columns must match rows and I can't find the answer so I don't know how to begin to try to do the code. So right now all I would like to know is how does the multiplication work when the dimensions are different in the 2 arrays that are being multiplied. Any help that can be given will be greatly appreciated.

Thanks,

Dorothy

Is This A Good Question/Topic? 0

## Replies To: Another question about multiplying two-dimensional arrays(matrices)

### #2 letthecolorsrumble

• Student of The Sun

Reputation: 27
• Posts: 555
• Joined: 07-November 07

## Re: Another question about multiplying two-dimensional arrays(matrices)

Posted 13 March 2008 - 08:38 PM

You have to store the values of the product of 2 Matrices into another matrix. So if you understand matrix multiplication on paper, I think you will have less trouble programming it.

http://en.wikipedia...._multiplication

For starters you could perform a product of 2x2 Matrices; and then understand from there on.

Hope this helps. More questions? Keep posting!

### #3 1lacca

• code.rascal

Reputation: 44
• Posts: 3,822
• Joined: 11-August 05

## Re: Another question about multiplying two-dimensional arrays(matrices)

Posted 14 March 2008 - 03:37 AM

letthecolorsrumble, on 14 Mar, 2008 - 04:38 AM, said:

http://en.wikipedia...._multiplication

### #4 .Maleficus.

Reputation: 2
• Posts: 129
• Joined: 07-March 08

## Re: Another question about multiplying two-dimensional arrays(matrices)

Posted 14 March 2008 - 04:39 AM

In short, you can multiply a [6][4] by a [4][5], and the third ANSWER matrix will be a [6][5]. The two outer dimensions are taken and used to make the resulting matrix.

### #5 dspivey5257

Reputation: 0
• Posts: 6
• Joined: 09-March 08

## Re: Another question about multiplying two-dimensional arrays(matrices)

Posted 14 March 2008 - 09:48 PM

Thanks for your help. It's been almost 20 years since I have been in college so alot of the math has changed. I had to look up what matrices was and teach myself how they did work in math and with your help I was able to figure out how they work. I now have the code working. Thanks again for all your help.

Dorothy