function poisson03fig2
% Fig. 1.2a Book Illustration for Simple Poisson/Jump Process (3/2007)
%   RNG Simulation for P(t) = 1:K jumps with sample variation.
%   Generation is by Poisson Jump Exponentially distributed 
%      jump time increments T(k+1)-T(k), T(k+1) = kth jump time, 
%      T(1) := 0.
%
clc % clear variables, but must come before globals, 
%     else clears globals too.
fprintf('\nfunction poisson03fig2 OutPut:')
nfig = 0;
K = 10; KP = 2*K +1; % Include sample of K jumps only.
p = zeros(KP,1); kstates = 4; LT = zeros(KP,kstates);
% Begin Calculation:
for kstate = 1:kstates; % Test Multiple Simulated Sample Paths:
    LT(1,kstate) = 0; p(1) = 0; % Set initial scaled jump time 
    %                             and jump count.
    rand('state',kstate);  % Set initial state for repeatability 
    %                        or path change.
    DTe = -log(rand(K,1));  % Generate random vector of
    %                         K exponential variates.
    for k = 1:K % Simulated sample scaled jump times 
        %         LT(k+1) = lambda*T(k+1):
        LT(2*k,kstate) = LT(2*k-1,kstate) + DTe(k);
        LT(2*k+1,kstate) = LT(2*k,kstate);
        p(2*k) = p(2*k-1);
        p(2*k+1) = p(2*k-1) + 1;
    end
end
% Begin Plot:
nfig = nfig + 1;
scrsize = get(0,'ScreenSize'); % figure spacing for target screen
ss = [5.0,4.0,3.5]; % figure spacing factors
fprintf('\n\nFigure(%i):  Simulated Jump Sample Paths\n',nfig)
figure(nfig)
plot(LT(1:KP,1),p,'k-',LT(1:KP,2),p,'k:',LT(1:KP,3),p,'k-.' ...
    ,LT(1:KP,4),p,'k--','LineWidth',2);
title('Simulated Simple Jump Sample Paths'...
    ,'FontWeight','Bold','Fontsize',44);
ylabel('P(t), Poisson State'...
    ,'FontWeight','Bold','Fontsize',44);
xlabel('\lambda t, Scaled Time'...
    ,'FontWeight','Bold','Fontsize',44);
hlegend=legend('Sample 1','Sample 2','Sample 3','Sample 4'...
    ,'Location','Southeast');
set(hlegend,'Fontsize',36,'FontWeight','Bold');
set(gca,'Fontsize',36,'FontWeight','Bold','linewidth',3);
set(gcf,'Color','White','Position' ...
   ,[scrsize(3)/ss(nfig) 60 scrsize(3)*0.60 scrsize(4)*0.80]); %[l,b,w,h]
% End Code
