3.14 Make a histogram of data sampled from some probability distribution
This example uses the normal distribution. First random data is generated, then
histogram of the data is made.
Matlab do not have an option, (unless I missed it) to make a relative histogram (this is
where the total area is 1) but not hard to implement this.
| Mathematica
data = RandomReal[NormalDistribution[],1000];
Histogram[data,30,"ProbabilityDensity",
ImageSize -> 300]]
|
|
| Matlab
data = randn(1000,1);
numberOfBins = 20;
[freq,bin] = hist(data,numberOfBins);
binWidth = (bin(end)-bin(1))/numberOfBins;
currentArea = sum(binWidth*freq);
freq = freq/currentArea;
bar(bin,freq)
|
|
| Maple
restart;
with(Statistics):
nSamples:=1000:
data := Sample(RandomVariable(Normal(0, 1)),
nSamples):
plots[display](Histogram(data,bincount=20,
frequencyscale=relative));
|
|