Hi, One thing you can do:
x = rand(3,1);
x = abs(x).^2/norm(x,2)^2;
% sum(x)=1
Of course this will work for random numbers generated for any distribution with finite variance.
x = randn(100,1);
x = abs(x).^2/norm(x,2)^2;
Wayne
randfixedsum
As found on the file exchange (written by Roger Stafford.)
Any other scheme that others will offer fails to give a
uniformly distributed set of numbers. This includes the
commonly offered idea of generating a random set and
then scaling them to sum to 1, or translation by subtracting
off the mean.
John
for i=1:4
x = rand(1,3);
x = abs(x).^2/norm(x,2)^2
end
only one set of values appear within the variable editor (spreadsheet) for x appears. Any suggestions how to get all four repeat on the 'spreadsheet' in each row.
thanks
Hi, There's nothing to keep you from generating a matrix of random numbers.
x = randn(4,3);
for k = 1:size(x,1)
normx(k) = norm(x(k,:),2)^2;
end
invnormx = (1./normx)';
invnormx = repmat(invnormx,1,3);
x = abs(x).^2;
x = x.*invnormx;
% check sum(x,2)
Wayne