diff --git a/statistics/code/gaussianbins.m b/statistics/code/gaussianbins.m index 5f3cc6d..effe1fd 100644 --- a/statistics/code/gaussianbins.m +++ b/statistics/code/gaussianbins.m @@ -1,6 +1,6 @@ -x = randn( 100, 1 ); -bins1 = -4:2:4; -bins2 = -4:0.5:4; +x = randn( 100, 1 ); % generate some data +bins1 = -4:2:4; % large bins +bins2 = -4:0.5:4; % small bins subplot( 1, 2, 1 ); hold on; hist( x, bins1 ); @@ -10,6 +10,7 @@ ylabel('Frequeny') hold off; subplot( 1, 2, 2 ); hold on; +% normalize to the rigtht bin size: hist( x, bins1, 1.0/(bins1(2)-bins1(1)) ); hist( x, bins2, 1.0/(bins2(2)-bins2(1)) ); xlabel('x') diff --git a/statistics/code/gaussianpdf.m b/statistics/code/gaussianpdf.m index 6c33dc6..259d6c9 100644 --- a/statistics/code/gaussianpdf.m +++ b/statistics/code/gaussianpdf.m @@ -1,22 +1,30 @@ % plot Gaussian pdf: -dx=0.1 +dx=0.1; x = [-4.0:dx:4.0]; p = exp(-0.5*x.^2)/sqrt(2.0*pi); hold on -plot(x,p, 'linewidth', 10 ) +plot(x, p, 'linewidth', 10) +% show area of integral: +area(x((x>=x1)&(x<=x2)), p((x>=x1)&(x<=x2)), 'FaceColor', 'r' ) +hold off % compute integral between x1 and x2: -x1=1.0 -x2=2.0 -P = sum(p((x>=x1)&(x=x1)&(x=x1)&(r=x1)&(r