You are here: Symbol Reference > MtxVecTools Namespace > Classes > TMtxOptimization Class > public > TMtxOptimization.RealFunction Property
MtxVec VCL
ContentsIndex
PreviousUpNext
TMtxOptimization.RealFunction Property

Defines the function to be minimized.

Pascal
property RealFunction: TRealFunction;

Defines the function to be minimized. The RealFunction must be of the TRealFunction type. Before you write actual function, set the Parameters, Constants and PConstants array size by using the:

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]);
MtxOptimization->VariableParameters->SetIt(false,OPENARRAY(double,(1,1))); MtxOptimization->ConstantParameters->SetIt(false,OPENARRAY(double,(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.

Examples on GitHub
Copyright (c) 1999-2025 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!