-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Supporting algorithm 6 (VB).bas
79 lines (56 loc) · 2.21 KB
/
Supporting algorithm 6 (VB).bas
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Attribute VB_Name = "Module1"
'##############################################################################################
'# John Wiley & Sons, Inc. #
'# #
'# Book: Markov Chains: From Theory To Implementation And Experimentation #
'# Author: Dr. Paul Gagniuc #
'# Data: 01/09/2016 #
'# #
'# Description: #
'# Supporting algorithm 6. The computation of the steady state vector. The above formulas are #
'# used for computing the x and y components of the steady state vector. Note that iterations #
'# are not required. #
'##############################################################################################
Dim M(1 To 2, 1 To 2) As String
Private Sub main()
Dim v(0 To 1) As Variant
Call ExtractProb("SRRSRSRRSRSRRSS")
chain = 5
v(0) = 1
v(1) = 0
For i = 1 To chain
x = (v(0) * M(1, 1)) + (v(1) * M(2, 1))
y = (v(0) * M(1, 2)) + (v(1) * M(2, 2))
v(0) = x
v(1) = y
MsgBox "Day (" & i & ")=[" & v(0) & " - " & v(1) & "]"
Next i
End Sub
Function ExtractProb(ByVal s As String)
Eb = "S"
Es = "R"
For i = 1 To 2
For j = 1 To 2
M(i, j) = 0
Next j
Next i
TB = 0
TS = 0
For i = 2 To Len(s) - 1
DI1 = Mid(s, i, 1)
DI2 = Mid(s, i + 1, 1)
If DI1 = Eb Then r = 1
If DI1 = Es Then r = 2
If DI2 = Eb Then c = 1
If DI2 = Es Then c = 2
M(r, c) = Val(M(r, c)) + 1
If DI1 = Eb Then TB = TB + 1
If DI1 = Es Then TS = TS + 1
Next i
For i = 1 To 2
For j = 1 To 2
If i = 1 Then M(i, j) = Val(M(i, j)) / TB
If i = 2 Then M(i, j) = Val(M(i, j)) / TS
Next j
Next i
End Function