5.0

5.0 | 3 ratings Rate this file 27 downloads (last 30 days) File Size: 8.22 KB File ID: #9700

Random Vectors with Fixed Sum

by Roger Stafford

 

19 Jan 2006 (Updated 24 Jan 2006)

No BSD License  

Randomly and uniformly generates vectors with a specified sum and values in a specified interval.

Editor's Notes:

This file was a File Exchange Pick of the Week

Download Now | Watch this File

File Information
Description

This generates m random n-element column vectors of values, [x1;x2;...;xn], each with a fixed sum, s, and subject to a restriction a<=xi<=b. The vectors are randomly and uniformly distributed in the n-1 dimensional space of solutions. This is accomplished by decomposing that space into a number of different types of simplexes (the many-dimensional generalizations of line segments, triangles, and tetrahedra.) The 'rand' function is used to distribute vectors within each simplex uniformly, and further calls on 'rand' serve to select different types of simplexes with probabilities proportional to their respective n-1 dimensional volumes. This algorithm does not perform any rejection of solutions - all are generated so as to already fit within the prescribed hypercube.

MATLAB release MATLAB 5.2 (R10)
Zip File Content  
Other Files Theory_of_randfixedsum.doc,
randfixedsum.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
30 Jan 2006 John D'Errico

This took a bit of work to verify uniformity in a slice of an n-dimensional hypercube. I'm now confident that Roger has done what he claimed, having checked samplings in several different dimensions, as well as having thought through the process he used to generate the sampling.

01 Sep 2006 Mike Edwards

very useful! beautiful code!

03 Apr 2007 Per-Anders Ekström

Excellent!

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
random Roger Stafford 22 Oct 2008 08:12:56
fixedsum Roger Stafford 22 Oct 2008 08:12:56
ndimensional Roger Stafford 22 Oct 2008 08:12:56
simplex Roger Stafford 22 Oct 2008 08:12:56
hypercube Roger Stafford 22 Oct 2008 08:12:56
 

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