Dew MtxVec NET
MinBrent Routines
Summary
Minimizes single variable function.

Unit
Optimization

Declaration
Function MinBrent(ax, bx: TSample; Func: TRealFunction; const Consts: array of TSample; const ObjConst: array of TObject; out MinX: TSample): Integer;


Declaration
Function MinBrent(ax, bx: TSample; Func: TRealFunction; const Consts: array of TSample; const ObjConst: array of TObject; out MinX: TSample; MaxIter: integer; Accuracy: TSample = 1.0E-8; Verbose: TStrings = nil): Integer;
 Parameter  Description 
ax,bx Set ax and bx to define initial interval for minimum. 
Func Real function of single variable (must be of TRealFunction type) to be minimized. 
Consts,PConsts Additional Fun constant parameteres (can be/is usually nil). 
MinX Returns the position of function minimum. 
MaxIter Maximum allowed numer of minimum search iterations. 
Accuracy Desired minimum position tolerance. 
Verbose If assigned, stores Func, evaluated at each iteration step. 
Result
the number of iterations required to reach the solution(minimum) within given tolerance.
Description
Minimizes the function of one variable. This routine uses slightly modified version of the algol 60 procedure localmin, introduced by Richard Brent.
Categories
Optimization routines
 See Also 
TRealFunction 

Example 1

Problem: Find the minimum of the function of single variable by using the Brent method.
Solution: The function is defined by the following equation:

Uses MtxVec, Math387, Optimization; function Fun(Pars: TVec: Const Consts: Array of TSample; Const ObjConsts: Array of TObject): TSample; begin Result := Sin(Pars[0])+Sqr(Pars[0]+2); // note that Pars holds only one variable ! end; procedure Example; var Res,x : TSample; begin // initial estimates for x1 and x2 Res := MinBrent(-10,10,Fun,[],[],x,500,1e-8); // stop if Iters >500 or Tolerance < 1e-8 // Returns Res = -1.8582461797 end;
#include "MtxVecCpp.h" //MtxVecCPP.cpp must be included in the project #include "Math387.hpp" #include "Optimization.hpp" double __fastcall Fun(TVec * x, double const * c, const int c_Size, System::TObject* const * o, const int o_Size) { double* X = x->PValues(0); return Sin(X[0])+IntPower(X[0]+2,2); // note that Pars holds only one variable ! } void __fastcall Example(); { // initial estimates for x1 and x2 double x; int iter = MinBrent(-10,10,Fun,NULL,-1,NULL,-1,x,500,1.0E-8,NULL); // stop if Iters >500 or Tolerance < 1e-8 // returns res = -1.8582461797 }
private double Fun(TVec pars, double[] c, object[] o) { return Math.Sin(Pars[0])+Math387.IntPower(Pars[0]+2,2); // note that Pars holds only one variable ! } private void Example() { // initial estimates for x1 and x2 double x; double res = Optimization.MinBrent(-10,10,Fun,null,null,out x, 500,1e-8,null); // stop if Iters >500 or Tolerance < 1e-8 // Returns res = -1.8582461797 }


Copyright 2008 Dew Research
http://www.dewresearch.com