13 views (last 30 days)

Show older comments

Hi everybody,

I am looking for a way to create normally distributed numbers with a fixed sum.

I know the random fixed sum numer generator from FileExchange https://de.mathworks.com/matlabcentral/fileexchange/9700-random-vectors-with-fixed-sum.

However, I wasn't able to easily adjust it to my needs.

Basically, I want the same as randfixedsum with the addition that the function recevies values for mu and sigma as a vector of length n. I understand that using different standard deviations for n-different values will lead to unequal pairwise corrrelations between the generated values, but that's ok.

I understand it's maybe not a trivial problem. Any ideas?

Thanks

Jeff Miller
on 27 Jul 2021

Matt J
on 26 Jul 2021

Edited: Matt J
on 26 Jul 2021

Why not simply,

x(1:N-1)=randn(1,N-1);

x(N)=fixedValue-sum(x(1:N-1))

Matt J
on 27 Jul 2021

It's not so much a gaussian distribution with a fixed sum so much as it is a gaussian distribution with an another number in the same vector that offsets the sum.

I don't really see the distinction. It is clearly a Gaussian random vector and the sum is unvarying, as the test below shows

N = 10000;

fixedValue = 50;

for i=1:4

x(1:N-1)=randn(1,N-1);

x(N)=fixedValue-sum(x(1:N-1));

s=sum(x)

end

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!