【題目】利用二分法,計算下列函數(shù)在[a,b]范圍的實根,程序計算后的結(jié)果如圖1所示.
【題目】利用二分法,計算下列函數(shù)在[a,b]范圍的實根,程序計算后的結(jié)果如圖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 "此區(qū)間方程無解!"
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 "此區(qū)間方程無解!"
Else
rot = root(a,b)
End If
Text1(2).Text = rot
End Sub
數(shù)學(xué)人氣:757 ℃時間:2020-04-13 11:12:28
優(yōu)質(zhì)解答
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...
我來回答
類似推薦
- vb題: 用二分法求函數(shù)f(x)=x3-6x-1=0在x=2~5范圍內(nèi)的x=2附近的一個實根,其計算誤差為| x1-x2
- 誰給講下啥叫二分法求函數(shù)
- 如何利用計算器,用二分法求函數(shù)零點的近似值?舉例說明.
- 用二分法求函數(shù)x+exp的根
- 怎樣用計算器,是···計算器!來用二分法求函數(shù)零點?
- 軍蟻是不是最厲害的螞蟻
- It's quite n_____ for a person to refuse the offer of help from strangers.
- 在金屬中最善于傳熱的是---?
- 1、2、5、13、34、()括號里是多少找規(guī)律,🈶什么規(guī)律
- 水受到地球引力的作用,從高處到低處,這一現(xiàn)象中 ,受力物體是什么?施力物體是什么?
- 追加100分,數(shù)學(xué)
- 亞硝酸鈉溶于水的反應(yīng)化學(xué)方程式?
猜你喜歡
- 1Is this chair made ( ) wood?
- 2雞兔同籠,兔的只數(shù)是雞的3倍,共有腳280只.雞、兔各有多少只?
- 3提示的近義詞是什么
- 4為什么“泰山”是“TaiShan Mountain”而黃山卻是“Huang Mountain”呢?
- 5"愛蓮說“是誰寫的?
- 6有一根長方體木料體積是540立方分米,它的截面面積是20平方分米,這根木料的長應(yīng)是_米.
- 7如圖,小亮從A點出發(fā)前進10m,向右轉(zhuǎn)15°,再前進10m,又向右轉(zhuǎn)15°,這樣一直走下去,他第一次回到出發(fā)點A時,一共走了米數(shù)是( ?。?A.120 B.150 C.240 D.360
- 8電功率的公式:P=W/t=IUt/t=IU讀作?
- 9“自相矛盾”這個成語告誡人們什么道理?
- 10已知某件事每隔兩分鐘可能會發(fā)生一次,發(fā)生概率為15%,
- 11(2009?承德縣模擬)(甲、乙均不為0)甲數(shù)的14等于乙數(shù)的16,甲數(shù)的15和乙數(shù)的17比較,( ?。?A.甲數(shù)的15大 B.乙數(shù)的17大 C.可能是甲數(shù)的15大,也可能是乙數(shù)的17大 D.一樣大
- 12一道關(guān)于人數(shù)的數(shù)學(xué)題