*
二分法求方程的解
举报
发布于:2022-11-06
更新于:2022-11-06
0
538
作品介绍:
问题:二分法求方程x^3-2x-1=0的近似解,精度为0.0000 01
操作说明:
寻找两个值a和b,使得函数值异号 vb程序转化方法 Sub 二分法() a = 0 b = 5 p = 0.00001 Do Midl = (a + b) / 2 If f(Midl) = 0 Then Exit Do Else If f(Midl) > 0 Then b = Midl Else a = Midl End If End If Loop While b - a > p Cells(3, 2) = "方程的根是" & (a + b) / 2 Cells(3, 3) = (a + b) / 2 End Sub Private Function f(ByVal x As Single) As Single f = x ^ 3 - 2 * x - 1 End Function