Thread: how many ways exists in order to multiply n matrices?

  1. #1
    Registered User Amin sma's Avatar
    Join Date
    Mar 2012
    Posts
    5

    Post 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.
    Thanks for your help!

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    What does that even mean? What is considered a "way" to multiply matrices?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User Amin sma's Avatar
    Join Date
    Mar 2012
    Posts
    5
    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);
    }

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    So it's a simple question of permutation count? The name you should give "fn" is "factorial" or "fac", then.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    100
    Programming instructors suck at writing out assignments.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by CornedBee View Post
    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.

    Note: The assignment might be about this.
    http://en.wikipedia.org/wiki/Matrix_...multiplication

    Tim S.
    Last edited by stahta01; 03-29-2012 at 03:12 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #7
    Registered User
    Join Date
    Mar 2012
    Posts
    110
    Slightly confusing. I thought the post was about Fox's algorithm, Cannon's or something. How to properly divide a n matrix.

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by stahta01 View Post
    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.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2 Matrices multiply problem
    By ydan87 in forum C Programming
    Replies: 1
    Last Post: 01-22-2012, 12:48 AM
  2. Replies: 9
    Last Post: 04-01-2011, 04:13 PM
  3. Replies: 4
    Last Post: 03-06-2008, 03:38 PM
  4. what is the significance of low order and high order bits
    By Shadow12345 in forum Windows Programming
    Replies: 1
    Last Post: 11-16-2002, 11:46 AM
  5. how to multiply 2 matrices
    By newguy in forum C Programming
    Replies: 1
    Last Post: 10-29-2001, 03:48 AM

Tags for this Thread