normally random number generator with limited zone

tnx in advance, i have 3 random variables.that every of that 3 related to a another(*) one(of course)its random too.i use normal distribution generator for monte carlo simulation in matlab to produce RAndom number.but in some cases with mention to unlimited zone of generating random number my final data(*)will be negative.that is not accurate and unexplainable for my job(bearing capacity-geotechnical eng.)i choose normally dist. because its the best match for my data and bell type format of its distribution also help me and i have to use it..also i need to generate positive random number with this normal dist.i think i should find a way to limit this generator to produce random number between -1 & 1 or even find a way to use this distribution with desirable mean and standard deviation..

1 comentario

This question duplicates http://www.mathworks.com/matlabcentral/answers/2028-normal-random-number-generator-with-specified-zone

Iniciar sesión para comentar.

 Respuesta aceptada

Bruno Luong
Bruno Luong el 25 de Feb. de 2011

2 votos

This function will generate a normal distribution conditional by bounds:
http://www.mathworks.com/matlabcentral/fileexchange/23832-truncated-gaussian

10 comentarios

milad babaei
milad babaei el 26 de Feb. de 2011
sorry i can not run this code since every time matlab tell me this msg: input argument sigma is undefined.at line 4 5????? so what is that???plz help me
Bruno Luong
Bruno Luong el 26 de Feb. de 2011
Did you provide sigma?
Did you type
>> help TruncatedGaussian
and read the calling syntax?
Did you take a look at the example?
milad babaei
milad babaei el 1 de Mzo. de 2011
hi
sorry bother you dear..i am a fresh student at matlab...would i ask u to help me more ??how to input my data in your matlab code?????this is all of my one variant:450,570,660,800.
i want to generate gaussian random number in this range [450 800]...mean:620
std:147.65...
another group of my data: 2.7,3.8,4.8,16.3
mean:6.9.......std:6.324
tnx in advance
Bruno Luong
Bruno Luong el 1 de Mzo. de 2011
Here is a copy/paste example from the help file. Not really complicated to call a function.
sigma=2;
range=[-3 5]
[X meaneff sigmaeff] = TruncatedGaussian(sigma, range, [1 1e6]);
stdX=std(X);
fprintf('mean(X)=%g, estimated=%g\n',meaneff, mean(X))
fprintf('sigma=%g, effective=%g, estimated=%g\n', sigma, sigmaeff, stdX)
hist(X,64)
milad babaei
milad babaei el 1 de Mzo. de 2011
i have done like this:
sigma=147.65;
range=[450 800]
[X meaneff sigmaeff] = TruncatedGaussian(sigma, range, [1 1e6]);
stdX=std(X);
fprintf('mean(X)=%g, estimated=%g\n',meaneff, mean(X))
fprintf('sigma=%g, effective=%g, estimated=%g\n', sigma, sigmaeff, stdX)
hist(X,64)
it gives that error first:range and sigma are incompatible....but the answer is:for example mean(x):625...but my mean is 620 ...and...what should i do???? sorry this is my last question..help me to get throw it.
milad babaei
milad babaei el 1 de Mzo. de 2011
i have also run your example..and saw the nice bell shaped histogram(truncated normal dist.) but in this case mt hist like a uniform distribution???would i ask u to run my example in your code plz???and tell what is my problem??
with regards
this matter is so urgent to me ..unless i do not like bother u..
Bruno Luong
Bruno Luong el 1 de Mzo. de 2011
I run you example and there is nothing shocking to me. The function returns correctly the warning messages and the distribution fits with the parameters. How can I guess what do want as shape?
Unless if you want to generate a truncated bell shape where the peak of the pdf located at 620 (which is *NOT* the *mean*), and has the same *shape* as N(620,147.65) (the lastest parameter is *NOT* the standard deviation), then you might do that:
sigma = 147.65;
range = [450 800];
peakpos = 620;
[X meaneff sigmaeff] = TruncatedGaussian(-sigma, range-peakpos, [1 1e6]);
X = peakpos+X;
meaneff = peakpos+meaneff;
stdX=std(X);
fprintf('mean(X)=%g, estimated=%g\n',meaneff, mean(X))
fprintf('sigma=%g, effective=%g, estimated=%g\n', sigma, sigmaeff, stdX)
hist(X,64)
But again, I have no idea what kind of distribution you want to generate.
milad babaei
milad babaei el 2 de Mzo. de 2011
hi my friend.thank u so much.. i really appreciate. u read my mind...this new code u gave me exactly the one i need it(generate gaussian RN and fit the histogram with a bell shaped).there is another question :is there any way to use this new code to generate three diffrent data on a same loop (for loop)
milad babaei
milad babaei el 2 de Mzo. de 2011
I mean if i have three variable c,g,fi that each of them has e relation like this q:F(c,g,fi)...so i need to use a for loop to provide the distribution of q
milad babaei
milad babaei el 3 de Mzo. de 2011
if i want to use this new code(with peakpos) on that original m_file,where should i change??in which line???plz help mee

Iniciar sesión para comentar.

Más respuestas (1)

Manu R
Manu R el 25 de Feb. de 2011

1 voto

You should not choose a probability distribution and then restrict its range. It leads to all sorts of problems with your measures of randomness (higher order moments) being flawed later.
I suggest you pick a non-negative distribution that resembles the Gaussian on the positive scale. I'd point you to the Exponential distribution and the Nakagami distribution to start your research on, solely based on your description so far.
Then, you can use the Normal distribution to generate numbers for these other distributions through an inverse transform.

1 comentario

milad babaei
milad babaei el 26 de Feb. de 2011
hi
tnx for your guidance...in other words i need to Generate values from the normal distribution on the interval [a, b].

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by