早教吧作业答案频道 -->数学-->
题目利用二分法,计算下列函数在[a,b]范围的实根,程序计算后的结果如图1所示.OptionBase1PrivateFunctionfun1(xAsSingle)AsSinglefun1=x*x*x-3*x*x-2*x+1EndSubPrivateFunctionroot(aAsSingle,bAs
题目详情
【题目】利用二分法,计算下列函数在[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
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 1
Const wucha As Double = 0.000001
Private Function fun1(x As Single) As Single
fun1 = x * x * x - 3 * x * x - 2 * x + 1
End Function
Private Function root(a As Single,b As Single)
Dim rot As Single
f0 = fun1(a)
f1 = fun1(b)
If Abs(f0) < wucha Then
root = a 'a是解
ElseIf Abs(f1) < wucha Then 'b是解
'If Len(rot) Then rot = rot & "," & f1 Else rot = f1
root = b
ElseIf f0 * f1 > 0 Then '同号,有0个或2个解
If Abs(f0 - f1) < wucha Then '无解
root = "无解"
ElseIf Abs(f0) < Abs(f1) Then
root = root(a,(a + b) / 2)
Else
End If
ElseIf f0 * f1 < 0 Then '异号,有1个或3个解
If fun1((a + b) / 2) * f0 < 0 Then
root = root(a,(a + b) / 2)
Else
root = root((a + b) / 2,b)
End If
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)
Text1(2).Text = root(a,b)
Debug.Print fun1(Val(Text1(2).Text))
End Sub
'每次只找其中的一个
Option Base 1
Const wucha As Double = 0.000001
Private Function fun1(x As Single) As Single
fun1 = x * x * x - 3 * x * x - 2 * x + 1
End Function
Private Function root(a As Single,b As Single)
Dim rot As Single
f0 = fun1(a)
f1 = fun1(b)
If Abs(f0) < wucha Then
root = a 'a是解
ElseIf Abs(f1) < wucha Then 'b是解
'If Len(rot) Then rot = rot & "," & f1 Else rot = f1
root = b
ElseIf f0 * f1 > 0 Then '同号,有0个或2个解
If Abs(f0 - f1) < wucha Then '无解
root = "无解"
ElseIf Abs(f0) < Abs(f1) Then
root = root(a,(a + b) / 2)
Else
End If
ElseIf f0 * f1 < 0 Then '异号,有1个或3个解
If fun1((a + b) / 2) * f0 < 0 Then
root = root(a,(a + b) / 2)
Else
root = root((a + b) / 2,b)
End If
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)
Text1(2).Text = root(a,b)
Debug.Print fun1(Val(Text1(2).Text))
End Sub
看了 题目利用二分法,计算下列函数...的网友还看了以下:
计算:(a-2倍的根号ab+b)/(根号a-根号b)+b-a/根号a-根号b 2020-04-05 …
计算(根号a-根号b分之根号b+ a-b分之根号a *根号a+根号b分之a+2倍根号ab+b)÷( 2020-04-05 …
高一的指数幂的运算,计算题...根号下的(a+2倍根号下a-1)+根号下(a-2倍根号a-1)(a 2020-04-25 …
8、下图是一些物质的凝固点和沸点,根据下表,在我国各个地区都能测量气温的温度计是[]A.酒精温度计 2020-05-14 …
先化简,在计算:[1/(a+b)+1/(a-b)]÷2a/(a平方+2ab+b平方),其中a=1+ 2020-05-16 …
三道初二平方根的计算1.求式子x的平方根+x的平方根-1+x的平方根-2的最小值2.若(a的平方根 2020-05-17 …
设a,b都是正实数,且不等于根号2×b,证明根号2必在a/b和(a+2b/a+b)之间,并说明这两 2020-05-21 …
用C++设计一个程序,求出一元二次方程ax^2+bx+c=0的根系数a.b.c的值从键盘上输入.求 2020-06-27 …
根2加1分之1等于根2减1,根3加根2分之一等于根3减根2,根4减根3分之1等于根4减根3根5加根4 2020-12-17 …
已知三角形三边求面积已知:a.b.c.d都是正整数.证明:存在这样的三角形,它的三边等于根号里b的平 2021-02-07 …