-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRandomWalk.m
57 lines (51 loc) · 1.22 KB
/
RandomWalk.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
numX = 1000;
numY = 1000;
x = linspace(-10,10,numX);
y = linspace(-10,10,numY);
[x,y] = meshgrid(x,y);
z = zeros(size(x));
z = addGaussian(x,y,z,500,[0,0],[10 0; 0 10]);
A = cartesianGridGraph(100,100);
nodesX = [-10:20/100:10]+20/200;
nodesX(end) = [];
nodesY = nodesX;
nodeLocX = [];
for i = 1:length(nodesX)
nodeLocX = [nodeLocX ones(1,100)*nodesX(i)];
end
nodeLocY = [];
for i = 1:length(nodesY)
nodeLocY = [nodeLocY nodesY];
end
statDist = griddata(x,y,z,nodeLocX,nodeLocY);
statDist = statDist/sum(statDist);
statDist = reshape(statDist,length(statDist),1);
xval = phiInverse(A,statDist);
P = capPhi(xval,A);
display('PCalculated')
path = 10000/2+50;
for i = 1:100000
randVal = rand;
prevLoc = path(end);
nextLoc = 0;
rowsum = 0;
while rowsum < randVal
nextLoc = nextLoc+1;
rowsum = rowsum + P(prevLoc,nextLoc);
end
path = [path nextLoc];
end
pathX = nodeLocX(path)';
pathY = nodeLocY(path)';
figure(1)
clf
surf(x,y,z,'EdgeColor','none')
hold on
pathPlot = plot3(pathX,pathY,ones(size(pathX))*20,'LineWidth',3,'color','red');
pathPlot.Color(4) = 0.7;
view([0 90])
set(gcf, 'Position', [50, 50, 950, 900])
set(gca,'FontSize',20)
colormap('parula')
axis([-10 10 -10 10])
axis equal