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;