title: VBA root finding trough bisection
body: <p>My vba code keeps returning a value of 0 when I know the roots of my function are not 0. </p>
  
  <p>It's pretty simple code but I can't seem to debug it. Any idea where this error might be coming from??</p>
  
  <pre><code>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) &lt; 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
  </code></pre>