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

◆ Dfzero()

Sub Dfzero ( F As  LongPtr,
B As  Double,
C As  Double,
R As  Double,
Re As  Double,
Ae As  Double,
Info As  Long 
)

Solution of a single general nonlinear equation

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]FUser supplied function which evaluates f(x) for the equation f(x) = 0 defined as follows:
Function F(X As Double) As Double
F = computed function value f(x)
End Function
X should not be changed.
[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.
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()
Dim B As Double, C As Double, R As Double, Re As Double, Ae As Double
Dim Info As Long
B = 1: C = 3: R = B
Re = 0: Ae = 0
Call Dfzero(AddressOf FDfzero, B, C, R, Re, Ae, Info)
Debug.Print "X =", B
Debug.Print "Info =", Info
End Sub
Sub Dfzero(F As LongPtr, B As Double, C As Double, R As Double, Re As Double, Ae As Double, Info As Long)
Solution of a single general nonlinear equation
Example Results
X = 2.09455148154233
Info = 0