function poisson03fig3
% Fig. 1.2b Book Illustration for Simple Incremental (3/2007)
%   Poisson/Jump Process RNG Simulation for 
%      Delta{P}(t) = P(t+Delta{t})-P(t) = 1:K jumps 
%   with sample variation.
%   Generation is by Poisson Jump Zero-One Law: 
%         Prob(Delta{P}(t)=0] = 1-lambda*dt, 
%      assuming sufficiently small Delta{t}'s.
%
clc % clear variables, but must come before globals, 
%     else clears globals too.
clf % clear figures, else accumulative.
fprintf('\nfunction delpois03fig3 OutPut:')
nfig = 3;
figure(nfig);
scrsize = get(0,'ScreenSize'); % figure spacing for target screen
ss = [5.0,4.0,3.5]; % figure spacing factors
marks = {'k-','k:','k-.','k--'};
% marks = {'k-o','k:s','k-.^','k--d'};
K = 10; KS = 500;  KP = KS + 1; % Include first K jumps from total 
%                                 KS sample only.
kstates = 4; DP = zeros(KP,kstates); DT = zeros(KP,kstates);
% Begin Calculation:
for kstate = 1:kstates; % Test Multiple Simulated Sample Paths:
    k = 0; DP(1,kstate) = 0.0; DT(1,kstate) = 0;  % Set initial
    %                                               jump parms.
    rand('state',kstate-1);  % Set initial state for repeatability 
    %                          or path change.
    xu = rand(KS,1);  % Generate random vector of K uniform variates.
    dt = 0.05; lambda = 1.0; % Set time step and jump rate.
    ldt = lambda*dt; % one jump prob.
    xl = (1-ldt)/2;  xr = (1+ldt)/2; % Set centered jump probability
    %                                 thresholds, using centered 
    %                                 part of uniform distribution
    %                                 to avoid open end point bias.
    ip = 0; % Set plot counter.
    for i = 1:KS % Simulated sample scaled jump times 
        %          LT(k+1) = lambda*T(k+1):
        ip = ip + 1;
        if xu(i) <= xr && xu(i) >= xl % Get jump if prob. in [xl,xr].
            k = k + 1;
            DP(ip+1,kstate) = DP(ip,kstate);
            DT(ip+1,kstate) = DT(ip,kstate) + dt;
            ip = ip + 1;
            DP(ip+1,kstate) = DP(ip,kstate) + 1;
            DT(ip+1,kstate) = DT(ip,kstate);
        else
            DP(ip+1,kstate) = DP(ip,kstate);
            DT(ip+1,kstate) = DT(ip,kstate) + dt;
        end
        if k == K
            KP = ip + 1;
            fprintf('\n kstate = %i; i = %i points; k = %i jumps;' ...
                ,kstate-1,i,k);
            break;
        end
    end
    plot(DT(1:KP,kstate),DP(1:KP,kstate),marks{kstate} ...
        ,'LineWidth',2), hold on
end
% Begin Plot:
fprintf('\n\nFigure(%i):  Simulated Small \Delta{t} Jump Sample Paths\n' ...
    ,nfig)
title('Simulated Small \Delta{t} Simple Jump Sample Paths'...
    ,'FontWeight','Bold','Fontsize',44);
ylabel('\Delta{P}(t), Poisson State'...
    ,'FontWeight','Bold','Fontsize',44); 
xlabel('t,  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
