Figure 7 (page 12):
Histogram of 10,000 samples of y= sum_{i=1}^{10} x_i.
Code for Figure 7
Text of the GNU GPL.
main.m
clear('all'); close('all');
nsam = 10000;
nsum = 10;
x = rand(nsum,nsam);
y = sum(x);
nbins = 20;
figure(1);
hist (y,nbins);
figure(2);
hist (x(1,:), nbins);
[ny, ysam] = hist(y,nbins);
[ysamb, nyb] = obar(ysam, ny);
[nx1, x1sam] = hist(x(1,:), nbins);
[x1samb, nx1b] = obar(x1sam, nx1);
data = [ysamb, nyb, x1samb, nx1b];
mean(x(1,:))
var(x(1,:))
mean(y)
var(y)
save cenlim.dat data
/export/home/jbraw/courses/cbe255/content/util/common/obar.m
% Copyright (C) 1996, 1997 John W. Eaton
%
% This file is part of Octave.
%
% Octave is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2, or (at your option)
% any later version.
%
% Octave is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
% General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Octave; see the file COPYING. If not, write to the Free
% Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
% 02110-1301, USA.
% -*- texinfo -*-
% @deftypefn {Function File} {} bar (@var{x}, @var{y})
% Given two vectors of x-y data, @code{bar} produces a bar graph.
%
% If only one argument is given, it is taken as a vector of y-values
% and the x coordinates are taken to be the indices of the elements.
%
% If two output arguments are specified, the data are generated but
% not plotted. For example,
%
% @example
% bar (x, y);
% @end example
%
% @noindent
% and
%
% @example
% [xb, yb] = bar (x, y);
% plot (xb, yb);
% @end example
%
% @noindent
% are equivalent.
% @end deftypefn
%
% @seealso{plot, semilogx, semilogy, loglog, polar, mesh, contour,
% stairs, replot, xlabel, ylabel, and title}
% Author: jwe
function [xb, yb] = obar (x, y)
if (nargin == 1)
if (isvector (x))
len = 3 * length (x) + 1;
tmp_xb = zeros (len, 1);
tmp_yb = zeros (len, 1);
tmp_xb(1) = 0.5;
tmp_yb(1) = 0;
k = 1;
for i = 2:3:len
tmp_xb(i) = k-0.5;
tmp_xb(i+1) = k+0.5;
tmp_xb(i+2) = k+0.5;
tmp_yb(i) = x(k);
tmp_yb(i+1) = x(k);
tmp_yb(i+2) = 0.0;
k=k+1;
end
else
error ('bar: argument must be a vector');
end
elseif (nargin == 2)
if (isvector (x) && isvector (y))
xlen = length (x);
ylen = length (y);
if (xlen == ylen)
len = 3 * xlen + 1;
tmp_xb = zeros (len, 1);
tmp_yb = zeros (len, 1);
cutoff = zeros (1, xlen);
for i = 1:xlen-1
cutoff(i) = (x(i) + x(i+1)) / 2.0;
end
delta_p = cutoff(1) - x(1);
delta_m = delta_p;
tmp_xb(1) = x(1) - delta_m;
tmp_yb(1) = 0.0;
k = 1;
for i = 2:3:len
tmp_xb(i) = tmp_xb(i-1);
tmp_xb(i+1) = x(k) + delta_p;
tmp_xb(i+2) = tmp_xb(i+1);
tmp_yb(i) = y(k);
tmp_yb(i+1) = y(k);
tmp_yb(i+2) = 0.0;
if (k < xlen)
if (x(k+1) < x(k))
error ('bar: x vector values must be in ascending order');
end
delta_m = x(k+1) - cutoff(k);
k=k+1;
if (k < xlen)
delta_p = cutoff(k) - x(k);
else
delta_p = delta_m;
end
end
end
else
error ('bar: arguments must be the same length');
end
else
error ('bar: arguments must be vectors');
end
else
usage ('[xb, yb] = bar (x, y)');
end
if (nargout == 0)
plot (tmp_xb, tmp_yb);
else
xb = tmp_xb;
yb = tmp_yb;
end
Data files
cenlim.dat
# Created by Octave 3.8.1, Thu Aug 21 10:29:24 2014 CDT
# name: data
# type: matrix
# rows: 61
# columns: 4
1.343934270027035 0 0.0001324608277435968 0
1.343934270027035 1 0.0001324608277435968 508
1.69400019762252 1 0.05012583650850234 508
1.69400019762252 0 0.05012583650850234 0
1.69400019762252 6 0.05012583650850234 469
2.044066125218005 6 0.1001192121892611 469
2.044066125218005 0 0.1001192121892611 0
2.044066125218005 14 0.1001192121892611 479
2.39413205281349 14 0.1501125878700199 479
2.39413205281349 0 0.1501125878700199 0
2.39413205281349 44 0.1501125878700199 505
2.744197980408974 44 0.2001059635507786 505
2.744197980408974 0 0.2001059635507786 0
2.744197980408974 112 0.2001059635507786 507
3.094263908004459 112 0.2500993392315374 507
3.094263908004459 0 0.2500993392315374 0
3.094263908004459 258 0.2500993392315374 490
3.444329835599944 258 0.3000927149122962 490
3.444329835599944 0 0.3000927149122962 0
3.444329835599944 484 0.3000927149122962 479
3.794395763195428 484 0.3500860905930548 479
3.794395763195428 0 0.3500860905930548 0
3.794395763195428 797 0.3500860905930548 510
4.144461690790912 797 0.4000794662738136 510
4.144461690790912 0 0.4000794662738136 0
4.144461690790912 1194 0.4000794662738136 512
4.494527618386398 1194 0.4500728419545724 512
4.494527618386398 0 0.4500728419545724 0
4.494527618386398 1397 0.4500728419545724 490
4.844593545981882 1397 0.5000662176353312 490
4.844593545981882 0 0.5000662176353312 0
4.844593545981882 1543 0.5000662176353312 514
5.194659473577367 1543 0.5500595933160899 514
5.194659473577367 0 0.5500595933160899 0
5.194659473577367 1434 0.5500595933160899 494
5.544725401172851 1434 0.6000529689968486 494
5.544725401172851 0 0.6000529689968486 0
5.544725401172851 1112 0.6000529689968486 515
5.894791328768337 1112 0.6500463446776075 515
5.894791328768337 0 0.6500463446776075 0
5.894791328768337 769 0.6500463446776075 492
6.24485725636382 769 0.7000397203583661 492
6.24485725636382 0 0.7000397203583661 0
6.24485725636382 446 0.7000397203583661 484
6.594923183959306 446 0.7500330960391248 484
6.594923183959306 0 0.7500330960391248 0
6.594923183959306 240 0.7500330960391248 499
6.94498911155479 240 0.8000264717198836 499
6.94498911155479 0 0.8000264717198836 0
6.94498911155479 102 0.8000264717198836 531
7.295055039150275 102 0.8500198474006424 531
7.295055039150275 0 0.8500198474006424 0
7.295055039150275 39 0.8500198474006424 531
7.645120966745759 39 0.9000132230814011 531
7.645120966745759 0 0.9000132230814011 0
7.645120966745759 6 0.9000132230814011 483
7.995186894341243 6 0.9500065987621599 483
7.995186894341243 0 0.9500065987621599 0
7.995186894341243 2 0.9500065987621599 508
8.345252821936727 2 0.9999999744429185 508
8.345252821936727 0 0.9999999744429185 0