



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Option Explicit Dim A As Long Dim C As Long Dim M As Long Dim B As Integer Dim N As Long Dim I As Long Dim J As Long Dim L () As Integer
Private Sub Form_Load( ) optLCG.Value = True optDistribution.Value = True txtNvariates.Text = 10000 txtNbins.Text = 10 txtA.Text = 5 txtC.Text = 3 txtM.Text = 16 grdFDT.TextMatrix(0, 0) = "Bin Number" grdFDT.TextMatrix(0, 1) = "Frequency" End Sub
Private Sub cmdInitiate_Click( ) A = CInt(txtA.Text) C = CInt(txtC.Text) M = CInt(txtM.Text) B = CInt(txtNbins.Text) N = CInt(txtNvariates.Text)
ReDim L(B) grdFDT.Clear grdFDT.TextMatrix(0, 0) = "Bin Number" grdFDT.TextMatrix(0, 1) = "Frequency" grdFDT.Rows = B + 1 For I = 1 To B grdFDT.TextMatrix(I, 0) = I Next I End Sub
Private Sub cmdExit_Click( ) End
Private Sub cmdExecute_Click( ) Dim R As Single Dim S As Single
If optDistribution.Value = True Then For J = 1 To B L(J) = 0 Next J
For I = 1 To N R = B * Random For J = 1 To B If Int(R) = J - 1 Then L(J) = L(J) + 1 Next J Next I
For J = 1 To B grdFDT.TextMatrix(J, 1) = L(J) Next J Else ReDim L(6) For I = 1 To 6 L(I) = 0 Next I
R = Random I = 1 J = 1 One: I = I + 1 If I > N Then GoTo Three S = Random If R < S Then GoTo Two If J > 6 Then J = 6 L(J) = L(J) + 1 J = 1 R = S GoTo One Two: J = J + 1 R = S GoTo One Three: If J > 6 Then J = 6 L(J) = L(J) + 1
For J = 1 To 6 grdFDT.TextMatrix(J, 1) = L(J) Next J End If End Sub
Private Sub cmdInvoke_Click( ) Load frmMatLab frmMatLab.Show
Option Explicit Dim MatLab As Object
Dim AA(6, 6) As Long Dim BB(6) As Double
Private Sub cmdAssignA_Click( ) Call AssignMatrix (AA, "A") End Sub
Private Sub cmdAssignB_Click( ) Call AssignVector(BB, "B") End Sub
Public Sub AssignMatrix(U( ) As Long, Name As String) Dim I As Integer Dim J As Integer Dim V As String Dim Result As String
V = Name & "=[" For I = 1 To UBound(U) For J = 1 To UBound(U) V = V & U(I, J) & " " Next J V = Left(V, Len(V) - 1) & ";" Next I V = Left(V, Len(V) - 1) & "]"
Result = MatLab.execute(V) picMatLab.Print Result End Sub
Private Sub AssignVector(U( ) As Double, Name As String) Dim I As Integer Dim V As String Dim Result As String
V = Name & "=[" For I = 1 To UBound(U) V = V & U(I) & " " V = Left(V, Len(V) - 1) & ";" Next I V = Left(V, Len(V) - 1) & "]"
Result = MatLab.execute(V) picMatLab.Print Result
Private Sub cmdAssignR_Click( ) Dim I As Integer Dim L(6) As Double
For I = 1 To 6 L(I) = frmMain.grdFDT.TextMatrix(I, 1) Next I Call AssignVector(L, "R") End Sub
Private Sub cmdCalculate_Click( ) Dim I As Integer Dim V As String Dim N As Long Dim Result As String
N = CInt(frmMain.txtNvariates.Text)
V = "( R- " & CStr(N) & "B)'A*( R - " & CStr(N) & " * B) /" & CStr(N) Result = MatLab.execute(V) picMatLab.Print Result End Sub
Private Sub cmdClear_Click( ) picMatLab.Cls End Sub
Private Sub cmdReturn_Click( ) Me.Hide frmMain.Show End Sub
Private Sub Form_Load( ) Set MatLab = CreateObject("Matlab.Application")
AA(1, 1) = 4529 AA(1, 2) = 9045 AA(1, 3) = 13568 AA(1, 4) = 18091 AA(1, 5) = 22615 AA(1, 6) = 27892
AA(2, 1) = 9045 AA(2, 2) = 18097 AA(2, 3) = 27139 AA(2, 4) = 36187 AA(2, 5) = 45234 AA(2, 6) = 55789