Мой код VBA продолжает возвращать значение 0, когда я знаю, что корни моей функции не 0.VBA корень поиска корыто бисекция
Это довольно простой код, но я не могу отладить. Любая идея, откуда эта ошибка может возникнуть?
Option Explicit
Public Function Bisect(ByVal xlow As Double, ByVal xhigh As Double) As Double
Dim i As Integer
Dim xmid As Double
xmid = (xlow + xhigh)/2
For i = 1 To 100
If f(xlow) * f(xmid) < 0 Then
xhigh = xmid
xmid = (xlow + xhigh)/2
Else
xlow = xmid
xmid = (xlow + xhigh)/2
End If
Next i
Bisect = xmid
End Function
Function f(ByVal x As Double, Optional ByRef inputArray As Range) As Variant
Dim ca0 As Double
Dim v0 As Double
Dim k As Double
Dim e As Double
Dim ac As Double
Dim L As Double
inputArray(2, 2) = ca0
inputArray(3, 2) = v0
inputArray(4, 2) = k
inputArray(5, 2) = e
inputArray(6, 2) = ac
inputArray(7, 2) = L
f(x) = (v0/(k * ca0 * ac)) * ((2 * e * (1 + e) * Log(1 - x)) + (e^2 * x) + (((1 + e)^2 * x)/(1 - x))) - L
End Function