Uses Math387,
MtxVecTools;
// define the real function to be minimized
function BananaFunction(
const Pars:
TVec;
const Consts:
TVec;
const PConsts:
Array of TObject): double;
begin
BananaFunction := 100*Sqr(Pars[1]-Sqr(Pars[0]))+Sqr(1-Pars[0]);
end;
procedure Example(MtxOptim: TMtxOptimization);
begin
if Assigned(MtxOptim)
then
begin
// define two variables and their initial values
MtxOptim.VariableParameters.SetIt(false,[2,-1]);
// use BFGS optimization method
MtxOptim.OptimizationMethod := optBFGS;
// tolerance for MinValue and gradient calculation
// additional note : since we did not define the GradProc,
// the internal numerical gradient approximation will be used
MtxOptim.Tolerance := 2.0e-6;
MtxOptim.GradTolerance := 2.0e-6;
// function to be minimized
MtxOptim.RealFunction := BananaFunction;
// finally, calculate minimum
MtxOptim.Recalculate;
end;
end;