You are here: Symbol Reference > Dew Namespace > Dew.Math Namespace > Types > Dew.Math.TRealFunction Type
Dew Math for .NET
ContentsIndexHome
PreviousUpNext
Dew.Math.TRealFunction Type

Defines real scalar function of several variables.

Syntax
C#
Visual Basic
public delegate double TRealFunction([In] TVec Parameters, [In] TVec Constants, [In] object[] ObjConst);

MtxVec.cs

Parameters 
Description 
Parameters 
Function variables. 
Constants 
Array of additional constants which can be used in math formula. 
ObjConst 
Array of additional constants (pointers) which can be used in math formula. 

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]);

Function of one variable

Suppose we have a function of one variable: 

y = a*Sin(b+2*x), 

where x is a variable and a,b are two additional constants. Here is how we would define function y: TRealFunction

 

function y(const Pars: TVec; const Consts: TVec; Const Objects: Array of TObject): double; begin y := Consts[0]*Sin(Consts[1]+2.0*Pars[0]); end; ... // calculate y=y(2.5) and set a,b, constants to 3 and 2 respectively var constVec, parsVec: Vector; constVec := [3,2]; parsVec := [2.5]; y(parsVec,constsVec,[]);
double __fastcall y(const TVec * Parameters, const TVec * Constants, System::TObject* const * ObjConst, const int ObjConst_Size) { return Consts[0]*Sin(Consts[1]+2.0*Parameters[0]); } ... // calculate y=y(2.5) and set a,b, constants to 3 and 2 respectively sVector parsVec, constVec; parsVec.SetIt(1, false, OPENARRAY(double,(2.5))); constVec.SetIt(2, false, OPENARRAY(double,(3,2))); y(parsVec, constVec, NULL,-1);

Function of several variables 

Suppose we have a function of several variables: 

YMul = a*Sin(b+2*x1)+Sqr(x2), 

where x1,x2 are two variables and a,b are two additional constants. Here is how we would define function yMul: TRealFunction; 

 

function y(const Pars: TVec; const Consts: TVec; const OConsts: Array of TObject): double; begin y := Consts[0]*Sin(Consts[1]+2.0*Pars[0])+ Sqr(Pars[1]); end; ... // calculate YMul=YMul(1,1) and set a,b constants to 2 and 3 respectively. var constVec, parsVec: Vector; begin constVec := [3,2]; parsVec := [1,1]; result := yMul(parsVec,constVec,[]);
Copyright (c) 1999-2024 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!