求解方程x^6-5*x^5+3*x^4+x^3-7*x^2+7*x-20=0区间在【-2,5】的两个根的VB代码
求解方程x^6-5*x^5+3*x^4+x^3-7*x^2+7*x-20=0区间在【-2,5】的两个根的VB代码
Private Sub form_Click()
Dim x1,x2,xa,xb
x1 = -2:x2 = -1:x = -1.5
Do Until Abs(x ^ 6 - 5 * x ^ 5 + 3 * x ^ 4 + x ^ 3 - 7 * x ^ 2 + 7 * x - 20) If x ^ 6 - 5 * x ^ 5 + 3 * x ^ 4 + x ^ 3 - 7 * x ^ 2 + 7 * x - 20 > 0 Then
x1 = x:x = (x1 + x2) / 2
Else
x2 = x:x = (x1 + x2) / 2
End If
Loop
xa = x
x1 = 4:x2 = 5:x = 4.5
Do Until Abs(x ^ 6 - 5 * x ^ 5 + 3 * x ^ 4 + x ^ 3 - 7 * x ^ 2 + 7 * x - 20) If x ^ 6 - 5 * x ^ 5 + 3 * x ^ 4 + x ^ 3 - 7 * x ^ 2 + 7 * x - 20 x1 = x:x = (x1 + x2) / 2
Else
x2 = x:x = (x1 + x2) / 2
End If
Loop
xb = x
MsgBox "该方程在【-2,5】区间的两个零点的近似值分别是" & xa & "和" & xb
End Sub
Private Sub Form_Load()
Me.AutoRedraw = True
Me.Width = 8000
Me.Height = 8200
Me.Scale (-6,400)-(6,-400)
'x^6-5*x^5+3*x^4+x^3-7*x^2+7*x-20=0
Line (-6,0)-(6,0)
Line (0,400)-(0,-400)
For i = -5 To 5
Line (i,20)-(i,0)
CurrentX = CurrentX - 0.3
Print i
Next i
For x = -2 To 5 Step 0.001
j = x ^ 6 - 5 * x ^ 5 + 3 * x ^ 4 + x ^ 3 - 7 * x ^ 2 + 7 * x - 20
PSet (x,j)
Next x
End Sub