You are here: Symbol Reference > Optimization Namespace > Functions > Optimization.TrustRegion Function
MtxVec VCL
ContentsIndex
Example
Uses MtxExpr, Optimization, MtxVec, Math387; // Objective function, 4 variables, 4 f components procedure TestVFun(const x,f: TVec; const c: Array of double; const o: Array of TObject); begin f[0] := x[0] + 10.0*x[1]; f[1] := 2.2360679774997896964091736687313*(x[2] - x[3]); f[2] := (x[1] - 2.0*x[2])*(x[1] - 2.0*x[2]); f[3] := 3.1622776601683793319988935444327*(x[0] - x[3])*(x[0] - x[3]); end; procedure Example; var x,f: Vector; epsa: TEPSArray; sr: TOptStopReason; begin // Initial estimates for variabless x.SetIt(false,[3,-1,0,1]); // 4 components, size must match the TestVFun implementation above f.Size(4); // setup stopping criteria, use default values epsa[0] := 1.0E-5; epsa[1] := 1.0E-5; epsa[2] := 1.0E-5; epsa[3] := 1.0E-5; epsa[4] := 1.0E-5; epsa[5] := 1.0E-10; // Minimize TrustRegion(TestVFun,x,f,[],[],1000,100,epsa,0.0,sr); // x stores minimum position (variables) // f stores function value at minimum // sr stores stop reason end;
#include "MtxExpr.hpp" #include "Math387.hpp" #include "Optimization.hpp" void __fastcall TestVFun(TVec* const x, TVec* const f, const double * c, const int c_Size, System::TObject* const * o, const int o_Size) { double* X = x->PValues1D(0); f->Values[0] = X[0] + 10.0*X[1]; f->Values[1] = 2.2360679774997896964091736687313*(X[2] - X[3]); f->Values[2] = (X[1] - 2.0*X[2])*(X[1] - 2.0*X[2]); f->Values[3] = 3.1622776601683793319988935444327*(X[0] - X[3])*(X[0] - X[3]); } void __fastcall Example(); { Vector x,f; TEPSArray epsarr; TOptStopReason sr; // Initial estimates for variabless x->SetIt(false,OPENARRAY(double,(3,-1,0,1))); // 4 components, size must match the TestVFun implementation above f->Size(4,false); // setup stopping criteria, use default values epsarr[0] = 1.0E-5; epsarr[1] = 1.0E-5; epsarr[2] = 1.0E-5; epsarr[3] = 1.0E-5; epsarr[4] = 1.0E-5; epsarr[5] = 1.0E-10; // Minimize TrustRegion(TestVFun,NULL,x,f,NULL,-1,NULL,-1,1000,100,epsarr,0.0,sr); // x stores minimum position (variables) // f stores function value at minimum // sr stores stop reason }
Copyright (c) 1999-2025 by Dew Research. All rights reserved.