random numbers between a and b with specified mean and variance
27 visualizzazioni (ultimi 30 giorni)
James Tursa il 2 Set 2015
1) a + b*rand() creates a value between a and a+b, not between a and b.
2) The values will have a uniform distribution with mean and variance fixed depending on a and b. If you want other mean and variance values then you either need a different a and b or you need a different distribution. Please specify what exactly you want.
Più risposte (2)
Walter Roberson il 2 Set 2015
If you require your distribution to be probability zero outside of [a,b], the way that uniform random has all of its probability within a pre-defined range, then you need to be using a Beta distribution. Uniform random distribution is one case of the Beta distribution.
However, the mean and standard deviation of a beta distribution cannot be chosen arbitrarily: they are fixed by the choice of a and b. http://www.mathworks.com/help/stats/betastat.html
There is no other distribution that is 0 probability outside of the given interval. If [a, b] are intended to be the complete bounds with no chance of a random number outside [a,b] then you need a Beta (or the special Beta that is Uniform random).
You can truncate an infinite random distribution to [a,b], but if you generate from the result, the samples you generate will not have mean c or standard deviation d. For example,
function x = truncrandn(a,b,c,d,m,n)
x = c + d * randn(m,n);
x = min(b,max(a,x));
This will produce random numbers in the specified range but exactly a and exactly b will both be over-represented, and the distribution of the result will probably not have the correct mean and will definitely not have the correct standard deviation.
Greig il 3 Set 2015
As far as I aware there is no bounded probability distribution where the mean and variance are independent of each other, and independent of the distribution parameterization. I don't believe it is mathematically possible. The bounds impose constraints the variance and, if the distribution is not symmetric about the mean, they also influence the mean.
Perhaps if you give us some more information about your application, we might be able to help with some approximation that fits your use. That is, something similar to James Tursa's answer and comment above.