?? 二分法.frm
字號(hào):
VERSION 5.00
Begin VB.Form Form1
Caption = "二分法解方程"
ClientHeight = 3975
ClientLeft = 60
ClientTop = 345
ClientWidth = 7080
BeginProperty Font
Name = "Arial Black"
Size = 21.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
ScaleHeight = 3975
ScaleWidth = 7080
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton CmdRoot
Caption = "開(kāi)始求根"
Height = 615
Left = 2040
TabIndex = 5
Top = 3240
Width = 3495
End
Begin VB.TextBox Text2
Height = 735
Left = 4800
TabIndex = 3
Text = "2.5"
Top = 840
Width = 1335
End
Begin VB.TextBox Text1
Height = 735
Left = 1560
TabIndex = 1
Text = "2"
Top = 840
Width = 1335
End
Begin VB.Label Label3
Caption = "Sin(x)*2+3*Cos(x/5)-x^2=0"
Height = 615
Left = 240
TabIndex = 6
Top = 120
Width = 6495
End
Begin VB.Label lblRoot
Height = 495
Left = 480
TabIndex = 4
Top = 2280
Width = 6375
End
Begin VB.Label Label2
Caption = "X2:"
Height = 495
Left = 3600
TabIndex = 2
Top = 840
Width = 975
End
Begin VB.Label Label1
Caption = "X1:"
Height = 495
Left = 360
TabIndex = 0
Top = 840
Width = 975
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'二分法解方程,編制:曹新國(guó),2004-3-14
'最后修改于 2006-4-5
Private Sub cmdRoot_Click()
'二分法求f(x)=Sin(x)*2+3*Cos(x/5)-x^2在區(qū)間[2,2.5]內(nèi)的一個(gè)實(shí)根
Dim x1 As Double, x2 As Double, x As Double
x1 = Val(Text1) ' InputBox("輸入?yún)^(qū)間x1的值", "輸入框 ")
x2 = Val(Text2) ' InputBox("輸入?yún)^(qū)間x2的值", "輸入框")
x = x1
f1 = Sin(x) * 2 + 3 * Cos(x / 5) - x ^ 2
f2 = Sin(x) * 2 + 3 * Cos(x / 5) - x ^ 2
If f1 * f2 < 0 Then
Do
x = (x1 + x2) / 2
f = Sin(x) * 2 + 3 * Cos(x / 5) - x ^ 2
If (f * f1) >= 0 Then
x1 = x
f1 = f
End If
If (f * f1) <= 0 Then
x2 = x
f2 = f
End If
Loop While Abs(x1 - x2) > 1E-20
x = (x1 + x2) / 2
lblRoot = "x=" & Format(x)
Else
MsgBox "方程在此區(qū)間內(nèi)無(wú)根,請(qǐng)重新輸入?yún)^(qū)間"
End If
End Sub
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -