📄 积分演示.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "数值积分"
ClientHeight = 3915
ClientLeft = 60
ClientTop = 345
ClientWidth = 8670
LinkTopic = "Form1"
ScaleHeight = 3915
ScaleWidth = 8670
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "四维“球”"
Height = 495
Left = 1560
TabIndex = 10
Top = 3240
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "二元函数积分"
Height = 495
Left = 120
TabIndex = 9
Top = 3240
Width = 1455
End
Begin VB.TextBox Text3
Height = 375
Left = 120
TabIndex = 4
Top = 2580
Width = 2655
End
Begin VB.TextBox Text2
Height = 375
Left = 1440
TabIndex = 3
Top = 1560
Width = 1335
End
Begin VB.TextBox Text1
Height = 375
Left = 120
TabIndex = 2
Top = 1560
Width = 1095
End
Begin VB.ComboBox Cbofunc
Height = 300
Left = 120
TabIndex = 1
Text = "select"
Top = 600
Width = 2655
End
Begin VB.PictureBox PicFunc
BackColor = &H00FFFF80&
Height = 3555
Left = 3000
ScaleHeight = 3495
ScaleWidth = 5475
TabIndex = 0
Top = 120
Width = 5535
End
Begin VB.Label Label4
Caption = "被积函数"
Height = 255
Left = 120
TabIndex = 8
Top = 240
Width = 2655
End
Begin VB.Label Label3
Caption = "积分值"
Height = 255
Left = 120
TabIndex = 7
Top = 2160
Width = 2535
End
Begin VB.Label Label2
Caption = "终值"
Height = 255
Left = 1440
TabIndex = 6
Top = 1200
Width = 975
End
Begin VB.Label Label1
Caption = "初值"
Height = 255
Left = 240
TabIndex = 5
Top = 1200
Width = 975
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'积分演示程序。改编:曹新国,2004-3-14
'最后修改于 2006-4-5 晚。
DefDbl X-Z
Const PI = 3.14159265358979
Dim x0(10)
Dim x1(10)
Private Sub Cbofunc_Click()
Dim xx0, xx1, h, s, t, x, n%, i%
xx0 = x0(Cbofunc.ListIndex) '获得被积函数的初值
xx1 = x1(Cbofunc.ListIndex)
Text1.Text = xx0
Text2.Text = xx1
PicFunc.Cls
PicFunc.Scale (-0.5, 1.5)-(4, -1.2) '定义图形框系坐标
PicFunc.Line (-0.5, 0)-(4, 0) '画X轴
PicFunc.Line (0, 1.5)-(0, -1.2) '画Y轴
PicFunc.Line (xx0, 1)-(xx1, 1) 'y=1
PicFunc.Line (xx0, -1)-(xx1, -1) 'y=-1
PicFunc.Line (xx0, 0)-(xx0, 0.1) '画积分初值刻度和初值
PicFunc.CurrentX = xx0
PicFunc.CurrentY = -0.02
PicFunc.Print xx0
PicFunc.Line (xx1, -1)-(xx1, 1) '画积分终值刻度和终值
PicFunc.CurrentX = xx1
PicFunc.CurrentY = -0.02
PicFunc.Print xx1
n = 300 '积分面积为40等份
h = (xx1 - xx0) / n
s = 0
x = xx0
For i = 1 To n
Select Case Cbofunc.Text
Case "Sin"
t = (Sin(x) + Sin(x + h)) / 2
Case "Cos"
t = (Cos(x) + Cos(x + h)) / 2
Case "0.3*(x^2-x+1)"
t = 0.3 * (x ^ 2 - x + 1)
End Select
PicFunc.Line (x, 0)-(x, t) '画出该函数值
s = s + t * h '累加面积
x = xx0 + (xx1 - xx0) / n * i
Next i
Text3.Text = s
End Sub
Private Sub Command1_Click()
V = 0
dx = 1 / 200
dy = 1 / 200
For x = -1 To 1 Step 1 / 200
For y = -1 To 1 Step 1 / 200
z = 1 - (x ^ 2 + y ^ 2)
If z > 0 Then
vi = dx * dy * Sqr(z) * 2
V = V + vi
End If
Next y
Next x
MsgBox "单位球(r=1)体积V=" & V & vbCrLf & "精确值V=" & 4 * PI / 3
End Sub
Private Sub Command2_Click()
'广义积分学的n重积分知识,就能轻而易举地算出一个100维空间里的“正方体”(n维单纯形)的“体积”
'V(n)=a^n/n!(a边长,即体积等于a的n次方再除以n的阶乘)
'其中a≥X1+X2+……+Xn,Xi≥0
'另外,一个n维球的体积V(n)的计算公式是
'V(2m)=〔π^m)R^2m〕/(2m)! …… (n=2m) 〈1〉
'V(2m+1)=[2(2π)^m][R^(2m+1)]/(2m+1)!! ……(n=2m+1) 〈2〉
'
'学了微积分,任何一个人都算出四维球的体积1/2*Pi^2*R^4,表面积2*PI^2*R^3,由此还可以推广到5维,6维直至n维,你能不能归纳出来呢?
V = 0
dx = 1 / 50
dy = 1 / 50
dz = 1 / 50
For x = -1 To 1 Step 1 / 50
For y = -1 To 1 Step 1 / 50
For z = -1 To 1 Step 1 / 50
U = 1 - (x ^ 2 + y ^ 2 + z ^ 2)
If U > 0 Then
vi = dx * dy * dz * Sqr(U) * 2
V = V + vi
End If
Next z
Next y
Next x
MsgBox "四维单位球(r=1)的" & vbCrLf & "球体积V=" & V & vbCrLf & "精确值V=" & 1 ^ 4 * PI ^ 2 / 2
End Sub
Private Sub Form_Load()
Font.Size = 20
Cbofunc.AddItem "Sin"
Cbofunc.AddItem "Cos"
Cbofunc.AddItem "0.3*(x^2-x+1)"
x0(0) = 0: x1(0) = PI
x0(1) = 0: x1(1) = PI
x0(2) = 0: x1(2) = 2.2
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -