typedef double (*TRealFunction)(TVec *, TVec *, const DewArray<tObject *> &);
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]);
Examples
cpp
#include "MtxExpr.h"
#include "MtxVec.h"
#include "Units.Math387.h"
using namespace Dew;
using namespace Dew::Math;
using namespace Dew::Math::Units::Math387;
static double y(TVec* Pars, TVec* Consts, const DewArray<tObject*>& Objects)
{
return (*Consts)[0]*Sin((*Consts)[1] + 2.0*(*Pars)[0]);
}
// ...
void Example()
{
// calculate y=y(2.5) and set a,b, constants to 3 and 2 respectively
Vector constVec, parsVec;
constVec = {3, 2};
parsVec = {2.5};
y(parsVec, constVec, {});
}cpp
#include "MtxExpr.h"
#include "MtxVec.h"
#include "Units.Math387.h"
using namespace Dew;
using namespace Dew::Math;
using namespace Dew::Math::Units::Math387;
static double y(TVec* Pars, TVec* Consts, const DewArray<tObject*>& OConsts)
{
return (*Consts)[0]*Sin((*Consts)[1] + 2.0*(*Pars)[0]) + Sqr((*Pars)[1]);
}
// ...
void Example()
{
// calculate YMul=YMul(1,1) and set a,b constants to 2 and 3 respectively.
Vector constVec, parsVec;
double result;
constVec = {3, 2};
parsVec = {1, 1};
result = y(parsVec, constVec, {});
}