%Marcha aleatoria con barreras reflejantes clc; clear all; p=1/2; q=1-p; R=[0 1 0 0 0; q 0 p 0 0; 0 q 0 p 0; 0 0 q 0 p; 0 0 0 1 0]; N=10; x=zeros(N,5); x(1,:)=[0 0 1 0 0]; i=2 for i=2:N x(i,:)=x(i-1,:)*R; end; plot(x(:,3));