# how many ways exists in order to multiply n matrices?

• 03-29-2012
Amin sma
how many ways exists in order to multiply n matrices?
Hi guys
I have a program to write but no idea where to start from.

program:
write a program that tells how many ways exists in order to multiply n matrices. You know that in matrices a*b is not equal to b*a but in this program it doesn't matter.
• 03-29-2012
CornedBee
What does that even mean? What is considered a "way" to multiply matrices?
• 03-29-2012
Amin sma
I mean for example we have matrices A[3][3] and B[3][3]. There are two ways to multiply them as A*N and B*A. It is not important that the answer is true or not as we know that A*B is not equal to B*A in matrices. I found the answer as below.
Code:

```#include<iostream.h> fn(int n) { if(n==1||n==2) return (n); else if(n>2) return(n*fn(n-1)); } void main() { int n; cout<<"How many matrices do you want to multiply? "; cin>>n; cout<<fn(n); }```
• 03-29-2012
CornedBee
So it's a simple question of permutation count? The name you should give "fn" is "factorial" or "fac", then.
• 03-29-2012
jsrig88
Programming instructors suck at writing out assignments.
• 03-29-2012
stahta01
Quote:

Originally Posted by CornedBee
So it's a simple question of permutation count? The name you should give "fn" is "factorial" or "fac", then.

More complex than that.

Given A is a 10 × 30 matrix, B is a 30 × 5 matrix
IIRC, then AB is valid because 30 equals 30; results in a 10 X 5 matrix answer.
But, BA is not valid because 5 does not equal 10.

Note: My memory is far from perfect; been 10 years since I had linear algebra.

http://en.wikipedia.org/wiki/Matrix_...multiplication

Tim S.
• 03-30-2012
überfuzz
Slightly confusing. I thought the post was about Fox's algorithm, Cannon's or something. How to properly divide a n matrix.
• 03-30-2012
CornedBee
Quote:

Originally Posted by stahta01
More complex than that.

Given A is a 10 × 30 matrix, B is a 30 × 5 matrix
IIRC, then AB is valid because 30 equals 30; results in a 10 X 5 matrix answer.
But, BA is not valid because 5 does not equal 10.

The assignment doesn't describe the input format, though, and the OP seems to have interpreted it as being a single integer. In which case we would be talking about square matrices.