function branching(steps,coeffs)
% Usage: branching(steps,coeffs)
%
% The vector `coeffs' defines generating function, with highest power first.
% (Default coeffs as in Chapter 13 branching process examples.)
% Output:  
% picture for Example Oz2 in Chapter 13, with
% zigzag path having `steps' horizontal segments.


%  Default generating function g(s) = 1/6 +(3/6)s + (2/6)s^2
if (nargin < 2)
	coeffs=  [2 3 1]/6;
	fprintf(1,'Using generating function (1+3s+2s^2)/6\n');
end

% Calculate successive extinction probabilities
thetan = zeros(1,steps+1);  % initialize
for n = 2:steps+1

	thetan(n) = polyval(coeffs,thetan(n-1));
end

TT=[thetan;thetan];

 zigzagX = TT(2:2*steps+1);
 zigzagY =TT(3:2*steps+2);
 
tt = 0:.05:1;
gen = polyval(coeffs,tt);

axes('FontName','times','FontSize',18);
plot(tt,gen,tt,tt,zigzagX,zigzagY);
 
 text(0.5,0.5,'\bullet\leftarrow(0.5,0.5)','FontName','times','FontSize',18);
 
 label1(1)={'g_1(s)'};label1(2)={'  \downarrow'};
 text(0.15,0.35,label1,'FontName','times','FontSize',18);
 
label2(1)={'s'}; label2(2)={'\downarrow'};
text(0.67,0.75,label2,'FontName','times','FontSize',18);
 
 







