?? form1.frm
字號:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 2985
ClientLeft = 60
ClientTop = 450
ClientWidth = 4350
LinkTopic = "Form1"
ScaleHeight = 2985
ScaleWidth = 4350
StartUpPosition = 3 '窗口缺省
Begin VB.Frame Frame1
Height = 2655
Left = 120
TabIndex = 0
Top = 120
Width = 4095
Begin VB.TextBox Text5
BeginProperty Font
Name = "宋體"
Size = 9
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 270
Left = 2880
TabIndex = 10
Top = 2040
Width = 1095
End
Begin VB.TextBox Text4
BeginProperty Font
Name = "宋體"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 270
Left = 1680
TabIndex = 4
Top = 1680
Width = 1095
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "宋體"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 1680
TabIndex = 3
Top = 960
Width = 615
End
Begin VB.TextBox Text2
BeginProperty Font
Name = "宋體"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 1680
TabIndex = 2
Top = 1320
Width = 1095
End
Begin VB.TextBox Text3
BeginProperty Font
Name = "宋體"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 270
Left = 1680
TabIndex = 1
Top = 2040
Width = 1095
End
Begin VB.Label Label1
Caption = "懲罰函數(shù)法"
BeginProperty Font
Name = "宋體"
Size = 15
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 0
Left = 240
TabIndex = 9
Top = 360
Width = 2415
End
Begin VB.Label Label1
Caption = "迭代精度"
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Index = 2
Left = 240
TabIndex = 8
Top = 1320
Width = 1455
End
Begin VB.Label Label1
Caption = "最優(yōu)函數(shù)值"
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Index = 11
Left = 240
TabIndex = 7
Top = 1680
Width = 1455
End
Begin VB.Label Label1
Caption = "最優(yōu)迭代點"
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Index = 10
Left = 240
TabIndex = 6
Top = 2040
Width = 1575
End
Begin VB.Label Label1
Caption = "迭代次數(shù)"
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Index = 1
Left = 240
TabIndex = 5
Top = 960
Width = 1215
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim X1 As Double '自變量
Dim X2 As Double '自變量
Private Sub Form_Load()
Dim f_x As Double '函數(shù)
Dim g_x As Double '約束
Dim c As Integer '經(jīng)驗值
Dim iterative As Integer '迭代次數(shù)
Dim ε As Double '迭代精度
f_x = X1 * X1 + X2 * X2 '函數(shù)表達式
g_x = 1 - X1 '約束
c = 4 '付初值
Mk = 10 '懲罰因子
ε = 0.00001 '迭代精度
iterative = 1
min_F_x_Mk (Mk) '調用函數(shù),求取最有解
If Abs(1 - X1) < ε Then '滿足迭代精度,即可退出
MsgBox ("迭代完畢!")
Text1.Text = iterative '輸出迭代次數(shù)
Text2.Text = ε '輸出迭代精度
Text3.Text = Format(X1, "0.000000") '輸出最有解
Text5.Text = Format(X2, "0.000000") '輸出最有解
f_x = X1 * X1 + X2 * X2 '函數(shù)表達式
Text4.Text = Format(f_x, "0.000000") '輸出最有值
Exit Sub
End If
Do While Abs(1 - X1) > ε '不滿足迭代精度,繼續(xù)迭代
Mk = Mk * c '加大懲罰力度
min_F_x_Mk (Mk) '調用函數(shù),求取最有解
If Abs(1 - X1) < ε Then '滿足迭代精度,即可退
MsgBox ("迭代完畢!")
Text1.Text = iterative '輸出迭代次數(shù)
Text2.Text = ε '輸出迭代精度
Text3.Text = Format(X1, "0.000000") '輸出最有解
Text5.Text = Format(X2, "0.000000") '輸出最有解
f_x = X1 * X1 + X2 * X2 '函數(shù)表達式
Text4.Text = Format(f_x, "0.000000") '輸出最有值
Exit Do
End If
iterative = iterative + 1 '迭代次數(shù)加1
Loop
End Sub
Function min_F_x_Mk(Mk)
X1 = 2 / (2 - 2 / Mk)
X2 = 0
End Function
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -