Results 1 to 2 of 2

Math Help - Fast algorithm for calculating permutations

  1. #1
    Newbie
    Joined
    Nov 2009
    Posts
    19

    Fast algorithm for calculating permutations

    I was wondering where I could find fast algorithms for calculating permutations. I tried using a matlab built in code perms() and it calculates a matrix of values. I would like to output each permutation individually (i.e. in a for loop) so i can perform some manipulations on them. Thanks in advance.

    MT
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Junior Member
    Joined
    Mar 2009
    Posts
    58
    You just need to iterate over your matrix. I'm using GNU Octave, but it's very close to MatLab so the same should work for you.

    Let's say you want the permutations of some matrix such as this:

    Code:
    a = [1, 2, 3, 4]
    Make the permutation matrix:

    Code:
    b = perms(a)
    Now you can iterate over it with something like:

    Code:
    for j = 1:size(b); b(j,:) endfor
    That's just printing the rows one by one (because I didn't put a semi-colon after the
    Code:
    b(j,:)
    but you can process each row as you go. Just do something right before the endfor.

    It's worthwhile to really get to know how to manipulate matrices in MatLab. That's pretty much how you do everything in it.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 3
    Last Post: February 21st 2010, 12:58 AM
  2. i need help fast....x
    Posted in the Trigonometry Forum
    Replies: 1
    Last Post: June 2nd 2008, 05:09 PM
  3. Need help fast
    Posted in the Statistics Forum
    Replies: 1
    Last Post: July 20th 2007, 06:30 PM
  4. I need fast HELP
    Posted in the Calculus Forum
    Replies: 3
    Last Post: August 6th 2006, 11:07 AM
  5. I need HELP FAST!!!
    Posted in the Algebra Forum
    Replies: 2
    Last Post: July 20th 2006, 09:49 AM

Search Tags


/mathhelpforum @mathhelpforum