【题目】利用二分法,计算下列函数在[a,b]范围的实根,程序计算后的结果如图1所示.

问题描述:

【题目】利用二分法,计算下列函数在[a,b]范围的实根,程序计算后的结果如图1所示.
Option Base 1
Private Function fun1(x As Single) As Single
fun1 = x * x * x - 3 * x * x - 2 * x + 1
End Sub
Private Function root(a As Single,b As Single) As Single
Dim rot As Single
f0 = fun1(a)
rot = (a + b) / 2
For Abs(a - rot) > 0.000001 Then
If f0 * fun1(rot) > 0 Then
root = root(rot,b)
Else
root = root(a,rot)
End If
Else
root = rot
End If
End Function
Private Sub Command1_Click()
Dim x As Single,a As Single,b As Single
a = Val(Text1(0).Text)
b = Val(Text1(1).Text)
f0 = fun1(a)
f1 = fun1(b)
If f0 * f1 = 0 Then
MsgBox "此区间方程无解!"
Else
rot = root(a,b)
End If
Text1(2).Text = rot
End Sub

0.3433796,-0.8342433,3.490864'每次只找其中的一个Option Base 1Const wucha As Double = 0.000001Private Function fun1(x As Single) As Singlefun1 = x * x * x - 3 * x * x - 2 * x + 1End FunctionPrivate Fun...