?? 最速下降法.frm
字號:
Left = 2280
Locked = -1 'True
TabIndex = 9
Text = "3*x1*x1+2*x1*x2+x2*x2+2*x1-2*x2+1"
Top = 240
Width = 4815
End
Begin VB.CommandButton Command2
Cancel = -1 'True
Caption = "退出"
Height = 495
Left = 6480
TabIndex = 7
Top = 6000
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "運(yùn)行"
Height = 495
Left = 6480
TabIndex = 6
Top = 5160
Width = 1215
End
Begin VB.TextBox Text3
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1920
TabIndex = 5
Text = "0.01"
Top = 3840
Width = 1575
End
Begin VB.TextBox Text2
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 5640
TabIndex = 4
Text = "0"
Top = 3120
Width = 1575
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1920
TabIndex = 3
Text = "0"
Top = 3120
Width = 1575
End
Begin MSScriptControlCtl.ScriptControl ScriptControl1
Left = 7320
Top = 1200
_ExtentX = 1005
_ExtentY = 1005
End
Begin VB.Label Label8
Alignment = 2 'Center
BackColor = &H00FF8080&
Caption = "計算次數(shù)"
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 300
Left = 360
TabIndex = 16
Top = 6480
Width = 1290
End
Begin VB.Label Label7
Alignment = 2 'Center
BackColor = &H00FF8080&
Caption = "輸出:"
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 300
Left = 360
TabIndex = 12
Top = 4680
Width = 1290
End
Begin VB.Line Line1
BorderWidth = 2
X1 = 0
X2 = 9000
Y1 = 4560
Y2 = 4560
End
Begin VB.Label Label6
Alignment = 2 'Center
BackColor = &H00FF8080&
Caption = "min f(x1,x2)"
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 300
Left = 360
TabIndex = 11
Top = 5880
Width = 1770
End
Begin VB.Label Label5
Alignment = 2 'Center
BackColor = &H00FF8080&
Caption = "(x1,x2)"
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 300
Left = 360
TabIndex = 10
Top = 5280
Width = 1290
End
Begin VB.Label Label4
Alignment = 2 'Center
BackColor = &H00FF8080&
Caption = "min f(x1,x2)"
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 240
TabIndex = 8
Top = 240
Width = 1815
End
Begin VB.Label Label3
Alignment = 2 'Center
BackColor = &H00FF8080&
Caption = "精度(e)"
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 300
Left = 360
TabIndex = 2
Top = 3960
Width = 1335
End
Begin VB.Label Label2
Alignment = 2 'Center
BackColor = &H00FF8080&
Caption = "初始點(diǎn)(x2)"
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 300
Left = 4080
TabIndex = 1
Top = 3240
Width = 1290
End
Begin VB.Label Label1
Alignment = 2 'Center
BackColor = &H00FF8080&
Caption = "初始點(diǎn)(x1)"
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 300
Left = 240
TabIndex = 0
Top = 3240
Width = 1290
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'最速下降法求極值
'研自0816 胡興武
Private Sub Command1_Click()
'定義h1,h2,h3,h4為海賽陣的按行拉直
'd1,d2為函數(shù)f(x)對x1,x2的偏導(dǎo)
'x1,x2為初始點(diǎn)
'r最佳步長
Dim x1, x2, e, r, f1, f2, h1, h2, h3, h4 As Single
Dim Count As Integer
Dim d1, d2 As String
e = ScriptControl1.Eval(Text3.Text) '精度要求
h1 = ScriptControl1.Eval(Text10.Text)
h2 = ScriptControl1.Eval(Text11.Text)
h3 = ScriptControl1.Eval(Text12.Text)
h4 = ScriptControl1.Eval(Text13.Text)
d1 = Text8.Text
d2 = Text9.Text
'計算初始點(diǎn)
f1 = ScriptControl1.Eval(Replace(Replace(d1, "x1", Text1.Text), "x2", Text2.Text))
f2 = ScriptControl1.Eval(Replace(Replace(d2, "x1", Text1.Text), "x2", Text2.Text))
While (Sqr(f1 * f1 + f2 * f2) > e) '比較兩邊界的差值是否小于精度要求
'迭代計算
r = (f1 * f1 + f2 * f2) / (h1 * f1 * f1 + h3 * f1 * f2 + h2 * f1 * f2 + h4 * f2 * f2) '計算最佳步長
'確定下一個近似點(diǎn)
x1 = x1 - r * f1
x2 = x2 - r * f2
f1 = ScriptControl1.Eval(Replace(Replace(d1, "x1", CStr(x1)), "x2", CStr(x2)))
f2 = ScriptControl1.Eval(Replace(Replace(d2, "x1", CStr(x1)), "x2", CStr(x2)))
Count = Count + 1
Wend
'輸出顯示
Text5.Text = "(" & Format(x1, "0.000000") & "," & Format(x2, "0.000000") & ")"
Text6.Text = Format(ScriptControl1.Eval(Replace(Replace(Text4.Text, "x1", CStr(x1)), "x2", CStr(x2))), "0.000000")
Text7.Text = Str(Count)
End Sub
Private Sub Command2_Click()
End
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -