how many ways exists in order to multiply n matrices?

This is a discussion on how many ways exists in order to multiply n matrices? within the C++ Programming forums, part of the General Programming Boards category; Hi guys I have a program to write but no idea where to start from. program: write a program that ...

  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,893
    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,893
    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
    2,610
    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.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  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,893
    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-21-2012, 11:48 PM
  2. Replies: 9
    Last Post: 04-01-2011, 04:13 PM
  3. Replies: 4
    Last Post: 03-06-2008, 02: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, 10:46 AM
  5. how to multiply 2 matrices
    By newguy in forum C Programming
    Replies: 1
    Last Post: 10-29-2001, 02:48 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21