% eda03_03
% Illustrate the calculatioon of the mean of a
% distribution p(d)

% Illustrative distribution p(d)
Dd = 1.0;
d = Dd*[0:14]' + 0.5*Dd;
p = [5.00, 15.00, 10.00, 10.00, 10.00, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00, 5.00]';

% normalize fistribution so its integral is unity
% note element-wise division
p = p./(Dd*sum(p));

% find mode of distribution p(d)
% the column-vector p contains the distribution
% the column-vector d contains the corresponding data values
themean = Dd*sum(d.*p);

% output to command window
disp(sprintf('mean = %f', themean));