% stick_split.m
%  A stick of length 1 is randomly split into two parts.
%  What is the average length of the shorter part?
%
n = input ( '  Enter N, number of tests: ' );
%
%  Do the experiment N times.
%  Add up in S the length of the shorter sticks.
%  Then average.
%
s = 0.0;

for k = 1 : n
%
%  Choose where to split the stick.
%
  x = rand ( );
  s = s + min ( x, 1.0 - x );

end
%
%  Now average.
%
s = s / n;

fprintf ( '  Average length of shorter stick is %g\n', s );

