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

◆ Dfmin()

Sub Dfmin ( A As  Double,
B As  Double,
F As  LongPtr,
Tol As  Double,
X As  Double 
)

Minimum of a single variable general nonlinear function

Purpose
This routine finds a minimum of a function f(x) between the given values A and B.

The method used is a combination of golden section search and successive parabolic interpolation. Convergence is never much slower than that for a Fibonacci search. If the function f has a continuous second derivative which is positive at the minimum (which is not at A or B), then convergence is superlinear, and usually of the order of about 1.324....

The function f is never evaluated at two points closer together than eps*abs(Dfmin) + (Tol/3), where eps is approximately the square root of the relative machine precision. If f is a unimodal function and the computed values of f are always unimodal when separated by at least eps*abs(xstar) + (Tol/3), then Dfmin approximates the abscissa of the global minimum of f on the interval [A, B] with an error less than 3*eps*abs(Dfmin) + Tol. If f is not unimodal, then Dfmin may approximate a local, but perhaps non-global, minimum to the same accuracy.
Parameters
[in]ALeft endpoint of initial interval.
[in]BRight endpoint of initial interval.
[in]FUser supplied function, which evaluates f(x) defined as follows:
Function F(X As Double) As Double
F = (computed function value f(x))
End Function
X should not be changed.
[in]TolDesired length of the interval of uncertainty of the final result. (Tol >= 0)
[out]XAbscissa approximating the point where f(x) attains a minimum on the interval [A, B].
Reference
D. Kahaner, C. Moler, S. Nash, "Numerical Methods and Software", Prentice-Hall (1989)
Example Program
Find the minimum point of the following function in the interval [0, 2].
f(x) = x^3 - 2x - 5
Function FDfmin(X As Double) As Double
FDfmin = X ^ 3 - 2 * X - 5
End Function
Sub Ex_Dfmin()
Dim A As Double, B As Double, Tol As Double, X As Double
A = 0: B = 2
Tol = 0.0000000001 '1.0e-10
Call Dfmin(A, B, AddressOf FDfmin, Tol, X)
Debug.Print "X =", X
End Sub
Sub Dfmin(A As Double, B As Double, F As LongPtr, Tol As Double, X As Double)
Minimum of a single variable general nonlinear function
Example Results
X = 0.816496587630398