題目是:x^3-3x^2+x=5
一個Button
一個Textbox
Button按下後方程式的根出現在Textbox裡面
(最多跑出九個根即可)
此vb程式碼該如何設計
2007-01-14 08:30:34 · 1 個解答 · 發問者 ? 2 in 電腦與網際網路 ➔ 程式設計
跑出來是錯誤的耶
宣告那裡要怎麼改??還是要改物件名稱什麼的??
2007-01-15 18:13:49 · update #1
本題的低限 請輸入 3
本題的高限 請輸入 4
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 "The root is " & c
End Sub
Public Function fun(x As Single) As Single
fun = x ^ 3 - 3 * x ^ 2 + x - 5
End Function
如果有問題, 請來函討論. 不然, 我可能會錯失你再補充的疑點.
2007-01-15 06:39:26 · answer #1 · answered by JJ 7 · 0⤊ 0⤋