30 likes | 188 Views
CIS 2033 based on Dekking et al. A Modern Introduction to Probability and Statistics. 2007 Slides by Longin Jan Latecki. C6:. GaussianEx1.m plots histogram of samples drawn from a Gaussian with mean zero and std one and plots the Gaussian with mean 1 and std 1.
E N D
CIS 2033 based onDekking et al. A Modern Introduction to Probability and Statistics. 2007Slides by Longin Jan Latecki C6:
GaussianEx1.m plots histogram of samples drawn from a Gaussian with mean zero and std one and plots the Gaussian with mean 1 and std 1. Values of histogram are normalized so that the sum of the area of the histogram bars (rectangles) is equal to 1. This way both plots are directly comparable, since the area under the Gaussian curve is also one. x = -5:0.1:5; g=normpdf(x,0,1); samples=randn(1000,1); %samples = normrnd(0,1,1000,1); [hs, hx] = hist(samples,x); hs=(hs/1000)*(101/10); figure; bar(x,hs,'r'); hold on plot(x,g,'LineWidth',3);
SamplingEx1.m plots histogram of samples drawn from exponential distribution and plots the exponential distribution Values of histogram are normalized so that the sum of the area of the histogram bars (rectangles) is equal to one. This way both plots are directly comparable. x = 0:0.1:10; lambda=1; f=lambda*exp(-lambda*x); %sample from uniform dist. U(0,1) samples=rand(1000,1); %samples = normrnd(0,1,1000,1); samples=-(1/lambda)*log(1-samples); [hs, hx] = hist(samples,x); hs=(hs/1000)*(101/10); figure; bar(x,hs,'r'); hold on plot(x,f,'LineWidth',3);