TRealFunction Delegate

Source: MtxVec.cs · Assembly: Dew.Math
MulticastDelegateTRealFunction

public delegate TRealFunction

Defines real scalar function of several variables.

Defines real scalar function of several variables.

What's the PConsts parameter for?

Constants can also be stored in a vector (or even matrix). In this case you could use the following code:

function YMul(const Pars: TVec; const Consts: TVec; const OConsts: Array of TObject): double;
begin
  YMul := Consts[0]*Sin(Consts[1] + 2.0*Pars[0]) + Sqr(Pars[1]);
end;
  ...

var constVec, parsVec: Vector;
begin
  constVec := [2,3];
  parsVec := [1,1];
  ...
  // calculate YMul=YMul(1,1) and set a,b constants to 2 and 3 respectively.
  result := yMul(parsVec, constVec, []);

or even:

function YMul(const Pars: TVec; const Consts: TVec; const ObjConsts:  Array of TObject): double;
  var CVec0 : TVec;
begin
  CVec0 := ObjConsts[0] as TVec;
  YMul := CVec0.Values[0]*Sin(CVec0.Values[1]+2.0*Pars[0])+ Sqr(Pars[1]);
end;

var constVec, parsVec: Vector;
begin
  ...
  constVec := [2,3];
  parsVec := [1,1];
  // calculate YMul=YMul(1,1) and set a,b constants to 2 and 3 respectively.
  yMul(parsVec,nil,[ConstVec]);