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

◆ Optif0()

Sub Optif0 ( N As  Long,
X() As  Double,
F As  LongPtr,
Xpls() As  Double,
Fpls As  Double,
Info As  Long 
)

Minimum of a multivariable nonlinear function (quasi-Newton method) (simple driver)

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 first order finite difference is used to compute the gradients, and the secant method (BFGS update) is used to compute the Hessian. The steps are computed by the line search.

Optif0 is equivalent to using Optif9 with setting default parameters. So that the problem is solved by the quasi-Newton method (BFGS method).
Parameters
[in]NThe order or dimension of the problem. (N > 1)
[in]X()Array X(LX - 1) (LX >= N)
Initial approximation of the 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, Fval As Double)
Calculate the function value from given N and X() and return in Fval. The other variables should not be altered.
End Sub
[out]Xpls()Array Xpls(LXpls - 1) (LXpls >= N)
Local minimum.
[out]FplsFunction value at local minimum Xpls.
[out]Info= 0: Successful exit.
= -1: The argument N had an illegal value. (N <= 1)
= -2: The argument X() is invalid.
= -4: The argument Xpls() is invalid.
= 1: Last global step failed to locate a point lower than Xpls. Either Xpls is an approximate local minimum of the function, the function is too nonlinear for this algorithm, or Steptl is too large.
= 2: Iteration limit (200) exceeded.
= 3: Maximum step size Stepmx exceeded five consecutive times. Either the function is unbounded below, becomes asymptotic to a finite value from above in some direction, or Stepmx is too small.
Reference
CMLIB
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 FOptif(N As Long, X() As Double, F As Double)
F = 100 * (X(1) - X(0) ^ 2) ^ 2 + (1 - X(0)) ^ 2
End Sub
Sub Ex_Optif0()
Const N As Long = 2
Dim X(N - 1) As Double, Xp(N - 1) As Double, Fp As Double
Dim Info As Long
X(0) = -1.2: X(1) = 1
Call Optif0(N, X(), AddressOf FOptif, Xp(), Fp, Info)
Debug.Print "X1, X2 =", Xp(0), Xp(1)
Debug.Print "Info =", Info
End Sub
Sub Optif0(N As Long, X() As Double, F As LongPtr, Xpls() As Double, Fpls As Double, Info As Long)
Minimum of a multivariable nonlinear function (quasi-Newton method) (simple driver)
Example Results
X1, X2 = 0.999990556479338 0.999981114653297
Info = 0