function wiener06fig1
% Fig. 1.1a Book Illustrations for Wiener/Diffusion Process (3/2007)
%   RNG Simulation for t in [0,1] with sample variation.
%   Generation is by summing Wiener increments DW of even spacing Dt.
clc % clear workspace of prior output.
clear % clear variables, but must come before globals, else clears them.
fprintf('\nfunction wiener06fig1 OutPut:'); % print code figure name
nfig = 0;
N = 1000; TF = 1.0; Dt = TF/N; % Set initial time grid: Fixed Delta{t}.
NP = N + 1; % Number of points.
sqrtdt = sqrt(Dt);  % Set standard Wiener increment moments'
% for dX(t) = mu*dt + sigma*dW(t); here mu = 0, sigma = 1 
%     and scaled dW(t) = sqrt(dt)*randn
% Begin Calculation:
tv = 0:Dt:TF; % time row-vector
nstate = 4; % number of states
jv = [1,2,3,4]; % selection of states; change when needed 
DWv = zeros(nstate,N); Wv = zeros(nstate,NP); % DW & W vectors/arrays;
% Also sets initial Wv(j,1) = 0;
for j = 1:nstate
    randn('state',jv(j)); % Set initial state for repeatability;
    DWv(j,1:N) = sqrtdt*randn(1,N);  %Generate N sample random row-vector;
    for i=1:N % Simulated Sample paths by Increment Accumulation:
        Wv(j,i+1) = sum(DWv(j,1:i)); % Note Wv(j,1) = 0.0; sum is effic.
    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):  Diffusion Simulated Sample Paths(4)\n' ...
    ,nfig)
figure(nfig)
marks = {'k-','k-o','k-^','k-x'}; % easier to change marks with nstate
%
for j = 1:nstate
    plot(tv,Wv(j,1:NP),marks{j},'linewidth',2); hold on;
end
hold off
%
title('Diffusion Simulated Sample Paths (4)'...
    ,'FontWeight','Bold','Fontsize',44);
ylabel('W(t), Wiener State'...
    ,'FontWeight','Bold','Fontsize',44);
xlabel('t, Time'...
    ,'FontWeight','Bold','Fontsize',44);
hlegend=legend('State 1','State 2','State 3','State 4'...
    ,'Location','SouthWest');
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
