Re: [VBA ] bisection 的 recursive
還是自問自答@@,又改了一下程式碼,這樣做好像比較符合了
只是把Function rebicon改了一下:
==============================
Function rebicon(n As Integer, xl As Double, xr As Double) As Double
Dim xm As Double
xm = (xl + xr) / 2#
If (infun(xl) = 0) Then
rebicon = xl
ElseIf (infun(xm) = 0) Then
rebicon = xm
ElseIf (infun(xr) = 0) Then
rebicon = xr
ElseIf (n > 1) Then
If (infun(xl) * infun(xm) < 0) Then
xr = xm
n = n - 1
ElseIf (infun(xm) * infun(xr) < 0) Then
xl = xm
n = n - 1
End If
MsgBox "xl = " & xl & " xm = " & (xl + xr) / 2# & " xr = " & xr
rebicon = rebicon(n, xl, xr)
End If
End Function
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.184.60.219
※ 編輯: tp6b123 來自: 111.184.60.219 (10/19 19:32)
討論串 (同標題文章)