function intdwdw % Fig. 2.1 Example MATLAB code for integral of (dW)^2 (3/2007): clc % clear variables; t0 = 0.0; tf = 1.0; n = 1.0e+4; nf = n + 1; % set time grid: (n+1) subintervals dt = (tf-t0)/nf; % and (n+2) points; % replace these particular values according the application; sqrtdt = sqrt(dt); % dW(i) noise time scale so E[dW] = 0; kstate = 1; randn('state',kstate); % Set randn state % for repeatability; dW = sqrtdt*randn(nf,1); % simulate (n+1)-dW(i)'s sample; t = t0:dt:tf; % get time vector t; W = zeros(1,nf+1); % set initial diffusion noise condition; sumdw2 = zeros(1,nf+1); % set initial integral sum; for i = 1:nf % simulate integral sample path. W(i+1) = W(i) + dW(i); % sum diffusion noise; sumdw2(i+1) = sumdw2(i) + (dW(i))^2; % sum whole integrand; end fprintf('\n\nFigure 1: int[(dW)^2](t) versus t\n'); nfig = 1; figure(nfig); scrsize = get(0,'ScreenSize'); % figure spacing for target screen ss = [5.0,4.0,3.5]; % figure spacing factors plot(t,sumdw2,'k-',t,t,'k--','LineWidth',2); % plot sum and t; title('\int(dW)^2(t) Simulations versus t'... ,'FontWeight','Bold','Fontsize',44); ylabel('\int(dW)^2(t) and t, States'... ,'FontWeight','Bold','Fontsize',44); xlabel('t, Time'... ,'FontWeight','Bold','Fontsize',44); hlegend=legend('\int(dW)^2(t)','t'... ,'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