Define a function of two variables and one additional constant parameter.
1) Set the VariableParameters, ConstantParameters size and (optionally) initial value:
MtxOptimization.VariableParameters.SetIt(false,[1,1]);
MtxOptimization.ConstantParameters.SetIt(false,[2.5]);
Note that all values are real.
2) Define the actual function:
function TestFunction(
const Pars:
TVec;
const Consts:
TVec;
const ObjConsts: Array of TObject):
double;
begin
TestFunction := 2*Pars[0]+Sqrt(Pars[1]-Consts[0]);
end;
double __fastcall BTestFunction(
TVec*
const Parameters,
TVec*
const Constants, System::TObject*
const * ObjConst,
const int ObjConst_Size)
{
double* Pars = Parameters->PValues1D(0);
return 2*Pars[0] + Sqrt(Pars[1]-Consts[0]);
}
Here Pars = VariableParameters.Values and Consts = ConstantParameters.Values.
3) "Connect" the function with TMtxOptimization component:
MtxOptimization.RealFunction := TestFunction;
MtxOptimization->RealFunction = TestFunction;
Please note that the internal algorithm does not check if Parameters, Constants, PConstants array size is the same as VariableParameters.Values, ConstantParameters.Values and SetPointers array size.