Not Yet Answered # How to multiply multiple matrices in c++?

Labdabeta 182 DavidB 44 Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

0

Okay... first of all this forum really isn't for just giving away free code, so I doubt anybody will just give you the solution. Now, I assume you are familiar with c++, but judging by your question it is hard to tell. For instance, how are you storing your matrices? is it `type matrix[width][height]`

? or maybe `type matrix[width*height]`

? or could it be `vector<vector<type>> matrix`

? We need more to go off of. On top of that, the way you asked the question makes me think that you haven't even tried to figure this one out yet. I assume you know how to multiply matrices, so try solving the most general case. IE: multiply

```
A B C ... X
D E F ... X
. . .
. . .
X X X
```

where A,B,C... are just variables. With this matrix:

```
a b c ... x
d e f ... x
. . .
. . .
x x x
```

While you are doing this think of what the constraints might be? Once you can solve the problem on paper, then you are ready to program it.

As for making the program user friendly, one thing that really helps with that is proper modularization in the code. You should break your code up into as many functions as makes sense. If any function does more than 1 distinct things, it should really be broken up into two things. EG:

```
int f(int a, int b)
{
return a+a*b;
}
//should become:
int add(int a, int b)
{
return a+b;
}
int mul(int a, int b)
{
return a*b;
}
int f(int a, int b)
{
int ret=mul(a,b);
return add(a,ret);
}
```

Obviously that is a silly code snippet, but it makes the point. Making functions then encourages you to basically make menus where the user just picks what function will be called. Typically you have them input a character to represent what they want to do (or a number if you prefer) then you use a switch statement to call the appropriate function.

Good Luck.

0

Do you mean you want to multiply A-matrix by B-matrix by C-matrix by D-matrix, etc.? You will have to do that one at a time.

Or do you mean you want the option of choosing among several different-sized matrices, but only two are going to be multiplied together?

Off the top of my head, I seem to recall that "Narue" posted a code block some time ago that did matrix multiplication. Just do a search of these forums.

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...