Hello,
How can I generate a uniformly distributed random vector with its sum to be equal to 1?
Thank you
probability random vector
5*24ans = 120>> 800*24ans = 19200>> (5 + 800)/2*24ans = 9660
a = 5;b = 800;(a + b)/2ans = 402.5
(b-a)^2/12ans = 52668.75
sumMean = (a+b)/2*24xmean = 9660sumVar = (b-a)^2/12*24xvar = 1264050sumStd = sqrt(sumVar)xstd = 1124.29978208661
sumLimits = [3550,3650];normcdf(sumLimits,sumMean,sumStd)ans = 2.74761306010529e-08 4.50716095152589e-08 diff(ans)ans = 1.7595478914206e-08
norminv(sumNormProbLimits(1) + rand()*diff(sumNormProbLimits),sumMean,sumStd)ans = 3637.00633112408
a = 5;b = 800;ndim = 24;sumMean = (a+b)/2*ndim;sumVar = (b-a)^2/12*ndim;sumStd = sqrt(sumVar);sumLimits = [3550,3650];sumNormProbLimits = normcdf(sumLimits,sumMean,sumStd);S = norminv(sumNormProbLimits(1) + rand()*diff(sumNormProbLimits),sumMean,sumStd);randfixedsum(24,1,S,a,b)ans = 32.6666351919248 226.171574450247 26.4486244673284 59.5273902733376 105.140425145937 198.085619814426 313.588691531256 125.527412419838 222.108869160278 78.6355991625287 116.832965448386 25.2315920517267 10.7762636314948 295.321051677379 339.225232904641 91.7004913938697 29.5858150543207 184.827862803465 37.7525635267701 115.866539562388 512.657889835195 372.544944227602 13.6087483202661 58.868132270981
sum(ans)ans = 3592.70093432559
runstest(cumsum(rand(1,100)))ans = 1runstest(mod(1:100,2))ans = 1
runstest(rand(1,1000))ans = 0
[h,p] = runstest(cumsum(rand(1,100)))h = 1p = 4.04395443273876e-29
x = rand(1,100);[h,p] = runstest(x)h = 0p = 0.838684318956303[h,p] = runstest([x,x])h = 0p = 0.720356034109542[h,p] = runstest([x,x,x])h = 0p = 0.64038079177353[h,p] = runstest([x,x,x,x])h = 0p = 0.578177151383335
[h,p] = runstest(rand(1,400))h = 0p = 0.72633274852919
Best Answer