function wiener06fig2 % Fig. 1.1b Book Illustration 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. clf % clear figures, else accumulative. clear % clear variables, but must come before globals, else clears them. fprintf('\nfunction wiener06fig2 OutPut:'); % print code figure name nfig = 1; N = 1000; TF = 1.0; Dt = TF/N; % Set time grids: Several dt's. NP = N+1; % Total number of Points. % for dX(t) = mu*dt + sigma*dW(t); here mu = 0, sigma = 1 % and scaled dW(t) = sqrt(dt)*randn % Begin Calculation: % nstate = 1; % number of states. ndt = 3; % number of local dt's. jv = [1,2,3,4]; % selection of states; change when needed randn('state',jv(1)); % Set common initial state for repeatability RN = randn(1,N); % common random sample of N points. Wv = zeros(ndt,NP); % W array of local vectors; % Also sets all Wv(kdt,1) = 0 for tv(1) = 0; recall MATAB is unit based. ts = zeros(ndt,NP); % Declare maximal local time vectors; %%%%% 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 kdt = 1:ndt % Test Multiple Sample Paths with different dt's: S = 10^(kdt-1); % dt scalar factor; Ns = N/S; NPs = Ns+1; % Local counts; Dts = S*Dt; % Local time steps; sigs = sqrt(Dts); % Local diffusion scaling; ts(kdt,1:NPs) = 0:Dts:TF; % Local times; for i = 1:Ns % Simulated Sample paths by Increment Accumulation: Wv(kdt,i+1) = Wv(kdt,i) + sigs*RN(1,i*S); end plot(ts(kdt,1:NPs),Wv(kdt,1:NPs),marks{kdt},'linewidth',2); hold on; end % hold off % title('Diffusion Simulations: \Delta{t} Effects'... ,'FontWeight','Bold','Fontsize',44); ylabel('W(t), Wiener State'... ,'FontWeight','Bold','Fontsize',44); xlabel('t, Time'... ,'FontWeight','Bold','Fontsize',44); hlegend=legend('\Delta{t} = 10^{-3}, N = 1000'... ,'\Delta{t} = 10^{-2}, N = 100' ... ,'\Delta{t} = 10^{-1}, N = 10','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