我为ln做了这个代码作为家庭作业,但它不适用于大于2的数字!
If Val(txt.Text) <= 0 Then
MsgBox "can't find ln !", vbExclamation + vbOKOnly, "ERROR": Exit Sub
Else
sign = -1
Sum = x - 1
r = 2
For j = 2 To 3 Step 0
t = sign * ((x - 1) ^ r / r)
If Abs(t) >= 0.0000001 And Abs(t) <= 100000000# Then
Sum = Sum + t
sign = -sign
r = r + 1
Else
GoTo 12
End If
Next
End If
这是等式的图像:
答案 0 :(得分:0)
非常感谢你的帮助,特别是MarkL,我做到了!而且我很高兴这个:)
如果您有兴趣,这里是最终代码^ _ ^:
If Val(txt.Text) <= 0 Then
MsgBox "can't find ln !", vbExclamation + vbOKOnly, "ERROR"
Exit Sub
ElseIf x < 0.51 Then
sign = -1
Sum = x - 1
For i = 2 To 500
t = sign * ((x - 1) ^ i / i)
If Abs(t) >= 0.0000001 Then
Sum = Sum + t
sign = -sign
Else
GoTo 12
End If
Next
Else
Sum = 0
For i = 1 To 600
t = ((x - 1) / x) ^ i
If Abs(t) < 10000000 Then
Sum = Sum + (t / i)
Else
GoTo 12
End If
Next
End If