clear all close all clc %% Part I p=0.25; % take 0 < p < 1/2 N=1000; M=1000; X=2*(rand(N,M)1 (and 0-a); % keeps track when S remains between -a and a T=T+A; % increments the time T as long as A=1 end ST=zeros(M,1); for m=1:M ST(m)=S(T(m),m); % value of S at time T end P=sum(ST==a)/M % probability that S(T)=a % theoretical value: P=1/(1+lambda^a) with lambda=(1-p)/p Tp=ones(1,M); % same thing as above, but this time for T' Ap=ones(1,M); for n=1:N-1 Ap=Ap.*(S(n,:)