No BSD License  

Highlights from
fpermute

3.0

3.0 | 1 rating Rate this file 0 Downloads (last 30 days) File Size: 230 Bytes File ID: #22265

fpermute

by Michal

 

28 Nov 2008

Derives a matrix of all possible permutations of natural numbers 1, 2, ... , N for a given N

| Watch this File

File Information
Description

I faced a stupid problem of getting all possible orders of variables for Cholesky decomposition of a covariance matrix. Web search offered advertisements of 60-line codes as a solution, so I decided to crack it myself. Enjoy.

MATLAB release MATLAB 6.5.1 (R13SP1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
11 Dec 2008 Tim Davis

A few suggestions. First and foremost, this code needs commenting. You have to look at the output matrix to figure out what matrix it's computing. This code has no comments at all. That's really the main reason I give it a rating of 3.

The second reason is that it needs to be redesigned. Wouldn't it make more sense to provide a function that returns each of the n! permutations one at a time? The matrix itself is huge. fpermute(10) returns a (10!)-by-10 matrix, about 3.6 million by 10. Surely an application doesn't need all 3.6 million permutations at the same time.

Something like:

k = 1
[p,k] = next_permutation(n,k)

which increments k. k=1 gives the first one (p=1:n), k=2 the next one, etc.

That would be a useful function. This one is limited by memory requirement to small values of n.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
mathematics Michal 01 Dec 2008 15:12:13
statistics Michal 01 Dec 2008 15:12:14

Contact us at files@mathworks.com