📄 d6r3.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4635
ClientLeft = 2655
ClientTop = 1950
ClientWidth = 6135
LinkTopic = "Form1"
ScaleHeight = 4635
ScaleWidth = 6135
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 375
Left = 4440
TabIndex = 0
Top = 3840
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
'PROGRAM D6R3
'Driver for routine RAN2
'Calculates pi statistically using volume of unit n-sphere
PI = 3.1415926
Dim IY(3), YPROB(3)
IDUM& = -1
For I = 1 To 3
IY(I) = 0
Next I
Print Tab(13); "Volume of unit n-sphere, n=2,3,4"
Print Tab(5); "# points PI (4/3)*PI (1/2)*PI^2"
For J = 1 To 15
For K = 2 ^ (J - 1) To 2 ^ J
x1 = RAN2(IDUM&)
x2 = RAN2(IDUM&)
x3 = RAN2(IDUM&)
x4 = RAN2(IDUM&)
If (FNC(x1, x2, 0#, 0#) < 1#) Then IY(1) = IY(1) + 1
If (FNC(x1, x2, x3, 0#) < 1#) Then IY(2) = IY(2) + 1
If (FNC(x1, x2, x3, x4) < 1#) Then IY(3) = IY(3) + 1
Next K
For I = 1 To 3
YPROB(I) = 1# * (2 ^ (I + 1)) * IY(I) / (2 ^ J)
Next I
Print Tab(5); 2 ^ J;
For M = 1 To 3
Print Tab(15 + (M - 1) * 14); Format$(YPROB(M), "#.#####0");
Next M
Next J
Print Tab(5); "actual"; Tab(15); Format$(PI, "#.#####0");
Print Tab(29); Format$(4# * PI / 3#, "#.#####0");
Print Tab(43); Format$(0.5 * (PI ^ 2), "#.#####0")
End Sub
Function FNC(x1, x2, x3, x4)
FNC = Sqr(x1 ^ 2 + x2 ^ 2 + x3 ^ 2 + x4 ^ 2)
End Function
Static Function RAN2(IDUM&)
M& = 714025: IA& = 1366: IC& = 150889: RM = 0.0000014005112
Dim IR&(97)
If IDUM& < 0 Or IFF = 0 Then
IFF = 1
IDUM& = (IC& - IDUM&) Mod M&
For J = 1 To 97
IDUM& = (IA& * IDUM& + IC&) Mod M&
IR(J) = IDUM&
Next J
IDUM& = (IA& * IDUM& + IC&) Mod M&
IY& = IDUM&
End If
J = 1 + Int((97 * IY&) / M&)
If J > 97 Or J < 1 Then Print "Abnormal exit": Exit Function
IY& = IR&(J)
RAN2 = IY& * RM
IDUM& = (IA& * IDUM& + IC&) Mod M&
IR&(J) = IDUM&
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -