any logic to do this programming on random number
Mostra commenti meno recenti
Hi,
I have generated 1000 random numbers from a normal distribution with std deviation=0.10 and mean=0.36
like
r=0.36+0.10*randn(1,1000)
now, I want to select 10 numbers from this random numbers, the summation of which will be in between 3.55 to 3.65..
I need 30 sets of such 10 numbers which sum will lie between this..3.55 to 3.65
any logic to do so
thanks
2 Commenti
Geoff Hayes
il 11 Giu 2014
Modificato: Geoff Hayes
il 11 Giu 2014
Note that the above equation is not quite correct (or your standard deviation and mean are reversed). If std is 0.1 and the mean is 0.36, then
r = 0.36+0.1*randn(1,1000);
Try std(r) and mean(r) to verify this.
joy
il 11 Giu 2014
Risposta accettata
Più risposte (1)
Sean de Wolski
il 11 Giu 2014
Modificato: Sean de Wolski
il 11 Giu 2014
I would take a different approach. First generate the 30 numbers who you must sum to:
xsum = rand(1,30)+3.55;
Example:
%%Desired sums
xsum = rand(1,30)+3.55;
%%build random numbers
rn = zeros(10,30);
for ii = 1:30
rn(:,ii) = randfixedsum(10,1,xsum(ii),0,xsum(ii));
end
%%verify
assert(norm(sum(rn)-xsum)<10^-14)
3 Commenti
John D'Errico
il 11 Giu 2014
Modificato: John D'Errico
il 11 Giu 2014
A flaw here is the numbers won't be at all normally distributed. Given the bound constraint on the mean, they won't be normally distributed anyway, but this gives up on any semblance of normality.
Sean de Wolski
il 11 Giu 2014
Ahh! Good catch.
Sean de Wolski
il 11 Giu 2014
I'll have to think about it a little more.
Categorie
Scopri di più su Resampling Techniques in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!