XLPack 6.0
Excel VBA Numerical Library Reference Manual
Loading...
Searching...
No Matches

◆ Mng()

Sub Mng ( N As  Long,
X() As  Double,
F As  LongPtr,
G As  LongPtr,
Info As  Long,
Optional Itsum As  LongPtr = NullPtr,
Optional Info2 As  Long,
Optional NFcall As  Long,
Optional NGcall As  Long,
Optional Niter As  Long,
Optional Fval As  Double,
Optional Rtol As  Double = -1,
Optional Atol As  Double = -1,
Optional MaxFcall As  Long = 0,
Optional MaxIter As  Long = 0,
Optional Tuner1 As  Double = -1,
Optional Xctol As  Double = -1,
Optional Xftol As  Double = -1,
Optional Lmax0 As  Double = -1,
Optional Lmaxs As  Double = -1,
Optional Sctol As  Double = -1,
Optional Bias As  Double = -1 
)

Minimum of a multivariable nonlinear function (trust region method)

Purpose
This routine finds the local minimum point (xs1, xs2, ..., xsn) of general nonlinear function f(x1, x2, ..., xn) (a twice continuously differentiable real-valued function).

The user supplied analytic routines is used to compute the gradient of the objective function. The secant method (BFGS update) is used to compute the Hessian. Steps are computed by the double dogleg trust region method.
Parameters
[in]NThe number of variables. (N > 0)
[in,out]X()Array X(LX - 1) (LX >= N)
[in] Initial approximation of the solution vector.
[out] Obtained solution vector.
[in]FThe user-supplied subroutine which calculates the function f(x1, x2, ..., xn) defined as follows.
Sub F(N As Long, X() As Double, Nf As Long, Fval As Double)
Calculate the function value from given N and X() and return in Fval.
Nf is invocation counter. If given X() is out of bounds, Nf should be set to 0. The other variables should not be altered. For same X() values, same Nf will be passed to F and G.
End Sub
[in]GThe user-supplied subroutine which calculates the derivatives of the function f(x1, x2, ..., xn) defined as follows.
Sub G(N As Long, X() As Double, Nf As Long, Gval() As Double)
Calculate the derivative value df/dX(i) from given N and X() and return in Gval(i) (i = 0 to N-1).
Nf is invocation counter. If given X() is out of bounds, Nf should be set to 0. The other variables should not be altered. For same X() values, same Nf will be passed to F and G.
End Sub
[out]Info= 0: Successful exit. (See sub-code in Info2)
= -1: The argument N had an illegal value. (N < 1)
= -2: The argument X() is invalid.
= 7: Singular convergence. (Hessian near the current iterate appears to be singular)
= 8: False convergence. (Iterate appears to be converging to a noncritical point. Tolerances may be too small)
= 9: Function evaluation limit reached.
= 10: Iteration limit reached.
= 63: F(X) cannot be computed at the initial X.
= 65: The gradient could not be computed at X.
[in]Itsum(Optional)
The user supplied subroutine to print the intermediate results defined as follows. (default = NullPtr)
If the address is supplied (if Itsum <> NullPtr), the subroutine is called after every iteration.
Sub Itsum(N As Long, X() As Double, NIter As Long, Nf As Long, Ng As Long, Fval As Double)
Output the following information in desired format.
N: Number of variables.
X(): Current approximation of the solution vector.
NIter: Iteration counter.
Nf: Number of function calls of F.
Ng: Number of function calls of G.
Fval: F value at X().
End Sub
Argument values should not be altered.
[out]Info2(Optional)
Sub-code for Info = 0.
= 1: X convergence.
= 2: Relative function convergence.
= 3: Both X and relative function convergence.
= 4: Absolute function convergence.
[out]NFcall(Optional)
Number of function evaluations of F.
[out]NGcall(Optional)
Number of function evaluations of G.
[out]Niter(Optional)
Number of iterations.
[out]Fval(Optional)
Function value at the obtained solution vector X().
[in]Rtol(Optional)
Relative function convergence tolerance. (Eps <= Rtol <= 0.1) (default = 1e-10) (Eps: machine epsilon)
(If Rtol < Eps or Rtol > 0.1, the default value will be used)
[in]Atol(Optional)
Absolute function convergence tolerance. (default = 1e-20)
(If Atol < 0, the default value will be used)
[in]MaxFcall(Optional)
Maximum number of function evaluations of F. (default = 200)
(If MaxFcall <= 0, the default value will be used)
[in]MaxIter(Optional)
Maximum number of iterations. (default = 150)
(If MaxIter <= 0, the default value will be used)
[in]Tuner1(Optional)
Parameter to check for false convergence. (0 <= Tuner1 <= 0.5) (default = 0.1)
(If Tuner1 < 0 or Tuner1 > 0.5, the default value will be used)
[in]Xctol(Optional)
X convergence tolerance. (0 <= Xctol <= 1) (default = Eps^(1/2))
(If Xctol < 0 or Xctol > 1, the default value will be used)
[in]Xftol(Optional)
False convergence tolerance. (0 <= Xftol <= 1) (default = 100*Eps)
(If Xftol < 0 or Xftol > 1, the default value will be used)
[in]Lmax0(Optional)
Maximum 2-norm allowed for scaled very first step. (Lmax0 > 0) (default = 1)
(If Lmax0 <= 0, the default value will be used)
[in]Lmaxs(Optional)
[in]Sctol(Optional)
Lmaxs and Sctol are the singular convergence test parameters. (Lmaxs > 0, 0 <= Sctol <= 1) (default: Lmaxs = 1, Sctol = 1e-10)
To test if the function reduction predicted for a step of length bounded by Lmaxs is at most Sctol*abs(f) (f is the function value at the start of the current iteration).
(If Lmaxs <= 0, the default value will be used)
(If Sctol < 0 or Sctol > 1, the default value will be used)
[in]Bias(Optional)
The bias parameter used in the dogleg trust region method. (0 <= Bias <= 1) (default = 0.8)
(If Bias < 0 or Bias > 1, the default value will be used)
Reference
netlib/port
Example Program
Find the minimum point of the following function (Rosenbrock function).
f(x1, x2) = 100(x2 - x1^2)^2 + (1 - x1)^2
The initial approximation is (x1, x2) = (-1.2, 1).
Sub FMng(N As Long, X() As Double, Nf As Long, F As Double)
F = 100 * (X(1) - X(0) ^ 2) ^ 2 + (1 - X(0)) ^ 2
End Sub
Sub GMng(N As Long, X() As Double, Nf As Long, G() As Double)
G(0) = -400 * X(0) * (X(1) - X(0) ^ 2) + 2 * X(0) - 2
G(1) = 200 * X(1) - 200 * X(0) ^ 2
End Sub
Sub Ex_Mng()
Const N = 2
Dim X(N - 1) As Double, Info As Long
X(0) = -1.2: X(1) = 1
Call Mng(N, X(), AddressOf FMng, AddressOf GMng, Info)
Debug.Print "X1, X2 =", X(0), X(1)
Debug.Print "Info =", Info
End Sub
Example Results
X1, X2 = 0.999999999986455 0.999999999971342
Info = 0