【发布时间】:2021-04-12 20:05:28
【问题描述】:
我的RootCheck2 旨在检查它实际上是根还是垂直渐近线。似乎忽略了第二个条件,因为代码当前正在输出渐近线和根。代码输出的Oldx 给出的fOldx 大于5,这让我相信它忽略了第二个条件。如有遗漏请告知,谢谢
Public Function SearchPsi(ByVal Variables As Range, ByVal x As Double) As Double
Dim Oldx As Double
Dim Checkx As Double
Dim fx As Double
Dim fOldx As Double
Dim fCheckx As Double
Dim RootCheck1 As Boolean
Dim RootCheck2 As Boolean
Do
Oldx = x
x = Oldx + 0.1
Checkx = Oldx + 0.01
fx = PSI(Variables, x)
fOldx = PSI(Variables, Oldx)
fCheckx = PSI(Variables, Checkx)
If (fx * fOldx) < 0 Then
RootCheck1 = True
End If
If Abs(fOldx) < 5 Then
RootCheck2 = True
End If
Loop Until RootCheck1 = True And RootCheck2 = True
SearchPsi = Oldx
End Function
【问题讨论】:
-
一旦
RootCheck1或RootCheck2变为True,它们将永远不会变为False,因为当你的条件不成立时,你永远不会将它们设置为False。
标签: excel vba loops conditional-statements