XLPack 7.0
XLPack Numerical Library (Excel VBA) Reference Manual
Loading...
Searching...
No Matches

◆ Dfzero_r()

Sub Dfzero_r ( B As  Double,
C As  Double,
R As  Double,
Re As  Double,
Ae As  Double,
Info As  Long,
XX As  Double,
YY As  Double,
IRev As  Long 
)

Solution of a single general nonlinear equation (reverse communication version)

Purpose
This routine searches for a zero of a function f(x) between the given values B and C until the width of the interval [B, C] has collapsed to within a tolerance specified by the stopping criterion, abs(B - C) <= 2*(Re*abs(B) + Ae).
It is designed primarily for problems where f(B) and f(C) have opposite signs. The method used is an efficient combination of bisection and the secant rule.
Parameters
[in,out]B[in] Lower endpoint of the initial interval.
[out] Lower endpoint of the final interval (the approximation to a zero).
[in,out]C[in] Upper endpoint of the initial interval.
[out] Upper endpoint of the final interval.
[in]RA (better) guess of a zero of f which could help in speeding up convergence. When no better guess is known, it is recommended that R be set to B or C.
[in]ReRelative error used for the stopping criterion. If the requested Re is less than machine precision, then it is set to approximately machine precision.
[in]AeAbsolute error used in the stopping criterion. If the given interval [B, C] contains the origin, then a nonzero value should be chosen for Ae.
[out]Info= 0: Successful exit.
= 1: f(x) = 0, however the interval may not have collapsed to the requested tolerance.
= 2: B may be near a singular point of f(x).
= 3: No change in sign of f(x) was found although the interval.
= 4: Too many (> 500) function evaluations used.
[out]XXIRev = 1: The abscissa where the function value shoule be evaluated and given in the next call
[in]YYIRev = 1: The function value f(XX) should be given in YY in the next call.
[in,out]IRevControl variable for reverse communication.
[in] Before first call, IRev should be initialized to zero. On succeeding calls, IRev should not be altered.
[out] If IRev is not zero, set the required values to the specified variables as follows and call the routine again.
= 0: Computation finished. See return code in Info.
= 1: User should set the function value at XX (f(XX)) in YY. Do not alter any variables other than YY.
Reference
D. Kahaner, C. Moler, S. Nash, "Numerical Methods and Software", Prentice-Hall (1989)
Example Program
Find the root of the following equation in the interval [1, 3].
x^3 - 2x - 5 = 0
Function FDfzero(X As Double) As Double
FDfzero = X ^ 3 - 2 * X - 5
End Function
Sub Ex_Dfzero_r()
Dim B As Double, C As Double, R As Double, Re As Double, Ae As Double
Dim Info As Long
Dim XX As Double, YY As Double, IRev As Long
B = 1: C = 3: R = B
Re = 0: Ae = 0
IRev = 0
Do
Call Dfzero_r(B, C, R, Re, Ae, Info, XX, YY, IRev)
If IRev <> 0 Then YY = FDfzero(XX)
Loop While IRev <> 0
Debug.Print "X =", B
Debug.Print "Info =", Info
End Sub
Sub Dfzero_r(B As Double, C As Double, R As Double, Re As Double, Ae As Double, Info As Long, XX As Double, YY As Double, IRev As Long)
Solution of a single general nonlinear equation (reverse communication version)
Example Results
X = 2.09455148154233
Info = 0