mean variance of uniform distribution over [0,1] MATLAB
Question
What is the best way in Matlab to get the mean and variance of a uniform distribution over [0,1]
?.
Solution
Mean and variance of an empirical distribution are calculated the same way for any distribution:
%# create uniform distribution
N = 1000;
dist = rand(N); %# N values, uniformly distributed between 0 and 1
%# calculate mean and variance
distributionMean = mean(dist);
distributionVariance = var(dist);
This approach provides an estimate for the mean and variance of the distribution from which your sample was drawn. Note that with larger N, distributionMean
will approach 0.5, and distributionVariance
will approach 1/12. If that's the values you're really interested in, the useful Matlab command is
web('http://en.wikipedia.org/wiki/Uniform_distribution_(continuous)')
OTHER TIPS
The mean and variance of a Uniform (0,1) or even a Uniform(a,b) random variable are known formulas.
For X~Uniform(a,b)
,
mean(X) = (a+b)/2
var(X) = (1/12)*((b-a)^2)
Set a = 0
and b = 1
for the desired result.
Read more here.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow