Hi,
I would like to create "random" paths starting from one known value and ending to another one. They should not be too extreme so I have limited that I don't accept paths who get over twice as big or half as small than starting and ending points.
I have partial solution but it doesn't work when StartPoint and EndPoint are equal as it forces all values to be equal (forcing to different values to be same results this be definition)…
Any ideas? Not need to be perfect, but I would like to generate some of these to compare case where we get from start point to end point via straight line.
PathLength=100;NumberOfSimulations=10;StartPoint=1000;EndPoint=2000;Saved=NaN*zeros(PathLength, NumberOfSimulations);n=0;while n~=NumberOfSimulations r =randn(PathLength,1); %Random nromally distributed numbers
c=cumsum(r); %Linear equation to scale values with start and end point
k=(EndPoint-StartPoint)/(c(end)-c(1)); b=StartPoint-k*c(1); d=c*k+b; if (max(d)>(2*max([StartPoint,EndPoint]))|| min(d)<min([StartPoint, EndPoint])/2); %not good path
else n=n+1; all(:,n)=d; endendfigure; hold on; plot(all) ; plot(mean(all,2),'k','Linewidth',2.5);
//Edit I found one solution but it is only for same size steps. Still need help.
%%http://cnr.lwlss.net/ConstrainedRandomWalk/
figure;close all;%Biased random walk
NumberOfSimulations=10;n=100; % number of steps, nt increasing and n(t-1) decreasing
x0=10; %StartPoint
xtarg=20; %End point after n steps
Saved=NaN*zeros(n+1,NumberOfSimulations+2);Saved(1,:)=x0;Saved(n+2,:)=xtarg;for q=1:NumberOfSimulations unifs=rand(n+1,1); x=x0; for i=0:(n-1) t =(1-(xtarg-x)/(n-i))/2; if unifs(i+1,1)<=t x=x-1; else x=x+1; end Saved(i+2,q)=x; endendfigure; hold on; plot(Saved) ; plot(mean(Saved,2),'k','Linewidth',2.5);
Best Answer