請問 X^5 - 3X^2 + X - 17 = 0
要怎麼用VB解出他的根?
2007-01-12 15:41:10 · 1 個解答 · 發問者 ALEX 1 in 電腦與網際網路 ➔ 程式設計
本題用二分逼近法解根 (1.920822)
Public Sub bisect()
Dim a As Single, b As Single, c As Single, e As Single, fx As Single
Dim done As Integer
e = 0.000001
a = InputBox("請輸入下限 a")
b = InputBox("請輸入上限 b")
done = 0
Do
c = (a + b) / 2
fx = fun(c)
If (Abs(fx) > e) Then
If (fx * fun(a) > 0) Then
a = c
Else
b = c
End If
Else
done = 1
End If
Loop While (done = 0)
Print "根為 " & c
End Sub
Public Function fun(x As Single) As Single
fun = x ^ 5 - 3 * x * x + x - 17
End Function
如果有問題, 請來函討論. 不然, 我可能會錯失你再補充的疑點.
2007-01-12 22:51:54 · answer #1 · answered by JJ 7 · 0⤊ 0⤋