求解方程x^6-5*x^5+3*x^4+x^3-7*x^2+7*x-20=0区间在【-2,5】的两个根的VB代码

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 15:46:10
求解方程x^6-5*x^5+3*x^4+x^3-7*x^2+7*x-20=0区间在【-2,5】的两个根的VB代码
xTkPW}ۦM'#+lSq S%Yo;$8d ܃AE}LqD6-Ǵi{2n2ac!~9';瞜Nemk`dtHfu-[RՋh#O95y{DX Ft_yީW\>1<ծ M|ئkә}~ߠ 3fJV9@xafY49؆{G0ov PLd8%Z s[`5:9_)R.G P"Vrc,OcN3,}r!r8jRS2,۶#S"YE)RJoDoW: 6Sb"іޠ ^|=J7nb&ʒ,n -F#&z]p%qZs6-OpU]3ҨT5e }tEn0",I&\&qРfv.*X8bu=g-ky@%*aqHT8LU8˓!R/U%\e#eVǰ*o

求解方程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代码

求解方程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) < 0.00001
  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) < 0.00001
  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
  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