急求,用vb编写程序,用普通迭代法求方程f(x)=x+lgx-2.5=0的近似实根r,迭代初值为1.5,精确到0.0001
1个回答
展开全部
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询