-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Supporting algorithm 12 (VB).bas
63 lines (48 loc) · 1.88 KB
/
Supporting algorithm 12 (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
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 12. Prediction based on a 3x3 transition matrix. #
'# Known transition probability values are directly used from a transition #
'# matrix for highlighting the behavior of an absorbing Markov Chain. #
'##############################################################################################
Dim Jar(1 To 3, 1 To 3) As String
Private Sub main()
Dim v(0 To 2, 0 To 1) As Variant
Jar(1, 1) = 0.33
Jar(1, 2) = 0.33
Jar(1, 3) = 0.33
Jar(2, 1) = 0.5
Jar(2, 2) = 0.5
Jar(2, 3) = 0
Jar(3, 1) = 0
Jar(3, 2) = 0
Jar(3, 3) = 1
chain = 5
v(0, 0) = 1
v(1, 0) = 0
v(2, 0) = 0
v(0, 1) = 0
v(1, 1) = 0
v(2, 1) = 0
For k = 1 To chain
For i = 0 To 2
For j = 0 To 2
v(i, 1) = v(i, 1) + (v(j, 0) * Jar(j + 1, i + 1))
Next j
Next i
For i = 0 To 2
v(i, 0) = v(i, 1)
v(i, 1) = 0
Next i
A = v(0, 0)
B = v(1, 0)
C = v(2, 0)
MsgBox "Step(" & k & ")=[" & A & " | " & B & " | " & C & "]"
Next k
End Sub