3.0

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

fpermute

by Michal

 

28 Nov 2008

No BSD License  

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

Download Now | 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
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com