Dew MtxVec NET
TMtxOptimization.SetObjects Method
Summary
Use SetObjects method to define any additional Object constant parameters in the RealFunction.

Class
TMtxOptimization

Declaration
Procedure SetObjects(const ObjConst: array of TObject);

Description
Use SetObjects method to define any additional Object constant parameters in the RealFunction. By default, the PConsts has 0 elements.
 See Also 
RealFunction 
VariableParameters 
ConstantParameters 

Example 1

The SetObject method provides an easy way to use all TVec and TMtx methods to construct function to be minimized:

Uses Math387, MtxVecTools; function MyFunction(Pars: TVec; const Consts: Array of TSample;const OConsts: Array of TObject): TSample; var tmpVec: TVec; begin tmpVec: = OConsts[0] as TVec; Result := Pars[0]*tmpVec.Sum -tmpVec.SumOfSquares*Pars[1]; end; begin // ... MtxOptimization.VariableParameters.SetIt(false,[-1,0]); MtxOptimization1.SetObjects([XVec]); // ... end;
#include "MtxVecCpp.h" #include "Math387.hpp" #include "MtxVecTools.hpp" // define the real function to be minimized double __fastcall VecFun(TVec * Parameters, const double * Constants, const int Constants_Size, System::TObject* const * ObjConst, const int ObjConst_Size) { double* pars = Parameters->PValues1D(0); TVec *tmpVec = dynamic_cast(ObjConst[0]); return (pars[0]*tmpVec->Sum() - pars[1]*tmpVec->SumOfSquares()); } void __fastcall Example(TMtxOptimization* opt1); { // ... opt1->RealFunction = VecFun; opt1->VariableParameters->SetIt(false,OPENARRAY(double,(-1,0))); Vector xVec; TObject* o[1]; o[0] = xVec; opt1->SetObjects(o,0); }
using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { // define the real function to be minimized private double vecfun(TVec pars, double[] consts, object[] objConsts) { TVec tmpVec = object0] as TVec; return pars[0]*tmpVec.Sum() -tmpVec.SumOfSquares()*pars[1]; } private void Example(TMtxOptimization opt1); { // ... opt1.RealFunction = VecFun; opt1.VariableParameters->SetIt(false,new double[] {-1,0)}); Vector xVec = new Vector(0); opt1.SetObjects(new object[] {xVec}); } }


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