作业帮 > 综合 > 作业

用vb编写程序,用普通迭代法求方程f(x)=x+lgx-2.5=0的近似实根r,迭代初值为1.5,精确到0.0001

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/22 10:57:27
用vb编写程序,用普通迭代法求方程f(x)=x+lgx-2.5=0的近似实根r,迭代初值为1.5,精确到0.0001
Private Sub Form_Load()
Me.AutoRedraw = True
Dim x#
x = 1.5
Do Until Abs(f(x)) < 0.0001
x = x - f(x) / df(x)
Loop
Print Format(x, "0.0000")
Print Format(f(x), "0.0000")
End Sub
Private Function f(x#) As Double
f = x + lg(x) - 2.5
End Function
Private Function df(x#) As Double
df = 1 + 1 / (x * Log(10))
End Function
Private Function lg(x#) As Double
lg = Log(x) / Log(10)
End Function