Post Reply 
New Root-Seeking Algorithms
04-04-2017, 02:39 PM (This post was last modified: 04-04-2017 02:43 PM by emece67.)
Post: #14
RE: New Root-Seeking Algorithms
You will also need to modify the stopping criterion as, simply relaying on the difference between the last two root estimations is not adequate. The convergence is, sometimes, so fast that at the 2nd or 3rd iteration, although being Abs(X - LastX) greater than Toler, the function does indeed evaluate to 0.

I ended up with:
Code:

  ' Ostrowski
  ' Count the number of function evaluation in detail
  Dim Tnfe As Long
  Tnfe = 0
  R = 2
  C = C + 2
  X = [A2].Value
  Do
    LastX = X
    h = 0.0000003 * (1 + Abs(X))
    F0 = Fx(sFx, X)
    Tnfe = Tnfe + 1
    ' Early Exit if root found
    If F0 = 0 Then
        Exit Do
    End If
    Fp = Fx(sFx, X + h)
    Tnfe = Tnfe + 1
    ' Early Exit if root found
    If Fp = 0 Then
        Cells(R, C) = X + h
        Cells(R, C + 1) = Fp
        R = R + 1
        Exit Do
    End If
    Deriv1 = (Fp - F0) / h
    Z = X - F0 / Deriv1
    Fz = Fx(sFx, Z)
    Tnfe = Tnfe + 1
    ' Early Exit if root found
    If Fz = 0 Then
        Cells(R, C) = Z
        Cells(R, C + 1) = Fz
        R = R + 1
        Exit Do
    End If
    X = Z - Fz * (X - Z) / (F0 - 2 * Fz)
    Cells(R, C) = X
    Cells(R, C + 1) = Fx(sFx, X)
    R = R + 1
  Loop Until Abs(X - LastX) < Toler Or R > 1000
  Cells(R + 1, C) = "Fx Calls="
  Cells(R + 1, C + 1) = Tnfe

I can confirm that the other methods do also benefit from decreasing the constant in the computation of h (your Hyper-Secant included. I've not tested the Super-Secant).
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
New Root-Seeking Algorithms - Namir - 04-02-2017, 09:28 PM
RE: New Root-Seeking Algorithms - pier4r - 04-02-2017, 09:54 PM
RE: New Root-Seeking Algorithms - Namir - 04-02-2017, 11:12 PM
RE: New Root-Seeking Algorithms - Namir - 04-02-2017, 11:15 PM
RE: New Root-Seeking Algorithms - bshoring - 04-03-2017, 09:23 PM
RE: New Root-Seeking Algorithms - Namir - 04-04-2017, 10:11 AM
RE: New Root-Seeking Algorithms - emece67 - 04-04-2017, 08:43 AM
RE: New Root-Seeking Algorithms - Namir - 04-04-2017, 01:13 PM
RE: New Root-Seeking Algorithms - ttw - 04-04-2017, 09:22 AM
RE: New Root-Seeking Algorithms - pier4r - 04-04-2017, 09:33 AM
RE: New Root-Seeking Algorithms - Namir - 04-04-2017, 10:14 AM
RE: New Root-Seeking Algorithms - ttw - 04-04-2017, 02:20 PM
RE: New Root-Seeking Algorithms - emece67 - 04-04-2017 02:39 PM
RE: New Root-Seeking Algorithms - Namir - 04-05-2017, 10:00 PM
RE: New Root-Seeking Algorithms - ttw - 04-06-2017, 01:51 AM
RE: New Root-Seeking Algorithms - Namir - 04-06-2017, 03:17 AM
RE: New Root-Seeking Algorithms - DMaier - 04-06-2017, 05:11 AM
RE: New Root-Seeking Algorithms - Namir - 04-06-2017, 09:05 AM
RE: New Root-Seeking Algorithms - ttw - 04-09-2017, 09:33 PM
RE: New Root-Seeking Algorithms - Namir - 04-10-2017, 05:01 AM
RE: New Root-Seeking Algorithms - Namir - 04-13-2017, 01:23 PM
RE: New Root-Seeking Algorithms - Namir - 04-15-2017, 10:58 PM
RE: New Root-Seeking Algorithms - robve - 11-25-2020, 09:44 PM
RE: New Root-Seeking Algorithms - Namir - 04-16-2017, 01:06 PM
RE: New Root-Seeking Algorithms - ttw - 04-20-2017, 05:05 AM



User(s) browsing this thread: 1 Guest(s)