Results 1 to 2 of 2

Thread: Fast algorithm for calculating permutations

  1. #1
    Nov 2009

    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.

    Follow Math Help Forum on Facebook and Google+

  2. #2
    Junior Member
    Mar 2009
    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:

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

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

    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
    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: Feb 20th 2010, 11:58 PM
  2. i need help fast....x
    Posted in the Trigonometry Forum
    Replies: 1
    Last Post: Jun 2nd 2008, 04:09 PM
  3. Need help fast
    Posted in the Statistics Forum
    Replies: 1
    Last Post: Jul 20th 2007, 05:30 PM
  4. I need fast HELP
    Posted in the Calculus Forum
    Replies: 3
    Last Post: Aug 6th 2006, 10:07 AM
  5. I need HELP FAST!!!
    Posted in the Algebra Forum
    Replies: 2
    Last Post: Jul 20th 2006, 08:49 AM

Search Tags

/mathhelpforum @mathhelpforum