%stchastic intergral simulation
dt=0.0001;
t=[0:dt:2];
n=size(t);
n=n(2);

clf reset;

Bmt = cumsum(sqrt(dt)*randn(1,n));
plot(t,Bmt(1:n),'Color',[0 0 1]);
hold on;

plot(t,0.5*(Bmt.^2-t),'Color',[0 1 0]); %check against explicit solition

inand=Bmt(1:n-1); %intergrand

%inand=inand.^2;
% inand=abs(Bmt(100+1:n+100-1));
% inand=sqrt(abs(Bmt([1:2:2*n-2])));
% inand=cumsum(sqrt(abs(Bmt([1:2:2*n-2]))))/n;

intor=Bmt(2:n)-Bmt(1:n-1); %integrator
pr=inand.*intor;
It=cumsum(pr); %integral

plot(t(1:n-1), It, 'Color',[1 0 0]);
legend('Bm', 'Int',-1);
hold on;

title('Stochastic Integral');