-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRmatrix.m
More file actions
30 lines (21 loc) · 1.15 KB
/
Copy pathRmatrix.m
File metadata and controls
30 lines (21 loc) · 1.15 KB
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
function R = Rmatrix(nump, PI, pstep)
% Calculates the transition matrix R
% (with the OFFSET DETERMINED by PI)
R = sparse(nump,nump);
nowoffset = log(PI)/pstep;
if nowoffset==0
R = eye(nump);
else
remoffset = nowoffset - floor(nowoffset);
R(1,1:ceil(nowoffset)) = 1;
startfirstdiag = [max([1 ; -floor(nowoffset)]) max([1 ; 1+ceil(nowoffset)])];
endfirstdiag = [min([nump-1 ; nump-ceil(nowoffset)]) min([nump ; nump+floor(nowoffset)])];
startsecdiag = [max([2 ; 1-floor(nowoffset)]) max([1 ; 1+ceil(nowoffset)])];
endsecdiag = [min([nump ; nump-ceil(nowoffset)+1]) min([nump ; nump+floor(nowoffset)])];
R(startfirstdiag(1):endfirstdiag(1),startfirstdiag(2):endfirstdiag(2)) = ...
remoffset*speye(nump-ceil(abs(nowoffset)));
R(startsecdiag(1):endsecdiag(1),startsecdiag(2):endsecdiag(2)) = ...
R(startsecdiag(1):endsecdiag(1),startsecdiag(2):endsecdiag(2)) + ...
(1-remoffset)*speye(nump-ceil(abs(nowoffset)));
R(nump,nump+floor(nowoffset)+1:nump) = 1;
end