CAMsymbolicFunction Class Reference

An instance of class CAMsymbolicFunction implements a double valued function (of an arbitrary number of double arguments) as specified by an initialization character string (i.e. symbolic initialization). More...

List of all members.

Public Member Functions

 CAMsymbolicFunction ()
 CAMsymbolicFunction (const CAMsymbolicFunction &F)
 CAMsymbolicFunction (char const *S)
 CAMsymbolicFunction (const char **V, int Vcount, char const *S)
 CAMsymbolicFunction (const char **V, int Vcount, const char **C, int Ccount, double const *Cvalues, char const *S)
 ~CAMsymbolicFunction ()
int initialize ()
int initialize (char const *S)
int initialize (const CAMsymbolicFunction &F)
int initialize (const char **V, int Vcount, char const *S)
int initialize (const char **V, int Vcount, const char **C, int Ccount, double const *Cvalues, char const *S)
void operator= (const CAMsymbolicFunction &F)
char * getConstructorString () const
int getVariableCount () const
char * getVariableName (int i) const
int getConstantCount () const
char * getConstantName (int i) const
double getConstantValue (int i) const
void setConstantValue (char *S, double x)
long getSymbolCount () const
double operator() (double x)
double operator() (double x1, double x2)
double operator() (double x1, double x2, double x3)
double operator() (double x1, double x2, double x3, double x4)
double operator() (double *x, int n)
double evaluate ()
char ** getVariableNamePtr () const
char ** getConstantNamePtr () const
double * getConstantValuePtr () const
void destroy ()
int create (const char **V, int Vcount, const char **C, int Ccount, double const *Cvalues, char const *S)
void initializeEvaluationData (const expressionTransform &T)
void initializeExecutionArray (const expressionTransform &T)
void setConstantEvaluationData ()

Static Public Member Functions

static void argError (int argC, int vCount)

Public Attributes

char ** sNames
char * constructorString
char ** variableNames
int variableCount
char ** constantNames
int constantCount
double * constantValues
long symbolCount
long * executionArray
long executionArraySize
double * evaluationData
long evaluationDataSize
void ** LibFunctions

Friends

__IMPEXP__ friend ostream & operator<< (ostream &out_stream, const CAMsymbolicFunction &F)


Detailed Description

An instance of class CAMsymbolicFunction implements a double valued function (of an arbitrary number of double arguments) as specified by an initialization character string (i.e. symbolic initialization).

The syntax for the initialization string is that of general C++ expressions. The initialization string can contain references to C++ math functions (those in math.h) as well as symbolic constants. The ^ character can be used to specify exponentiation, e.g. x^2 = x*x.

The () operator is overloaded so the standard functional evaluation syntax, e.g. f(x), is used to evaluate the CAMsymbolicFuntion instance.

Sample Usage:

int Vcount = 2;                   // number of independent variables
char*V []  = {"x","y"};           // x,y  = independent variable names
char*S     = "x^2 + 2*y";         // specify a function 
     
CAMsymbolicFunction F(V,Vcount,S); // initialize instance
    
cout << F(2.0,3.0) << endl;        // evaluate and output result at (x,y) = (2.0,3.0) 

Author:
Chris Anderson
Date:
7/21/97
Version:
01/26/07

Definition at line 26 of file symfun.h.


Constructor & Destructor Documentation

CAMsymbolicFunction::CAMsymbolicFunction (  ) 

Creates a "null" CAMsymbolicFunction. The CAMsymbolicFunction is initialized with the initialize member functions.

Definition at line 53 of file symfun.cpp.

CAMsymbolicFunction::CAMsymbolicFunction ( const CAMsymbolicFunction F  ) 

Copy constructor.

Definition at line 78 of file symfun.cpp.

CAMsymbolicFunction::CAMsymbolicFunction ( char const *  S  ) 

Creates a CAMsymbolicFunction in one variable, x, where the function is specified by the null terminated string S. If the construction process fails, program execution stops and an error message is output.

Definition at line 176 of file symfun.cpp.

CAMsymbolicFunction::CAMsymbolicFunction ( const char **  V,
int  Vcount,
char const *  S 
)

Creates a CAMsymbolicFunction of Vcount variables from the initialization string S. S is a null terminated character string. If the construction process fails, program execution stops and an error message is output.

Sample specification and use of a function of two variables x and y:

int Vcount = 2;                   // number of independent variables
char*V []  = {"x","y"};           // x,y  = independent variable names
char*S     = "x^2 + 2*y";         // specify a function 
     
CAMsymbolicFunction F(V,Vcount,S); // initialize instance
    
cout << F(2.0,3.0) << endl;        // evaluate and output result at (x,y) = (2.0,3.0) 

Definition at line 209 of file symfun.cpp.

CAMsymbolicFunction::CAMsymbolicFunction ( const char **  V,
int  Vcount,
const char **  C,
int  Ccount,
double const *  Cvalues,
char const *  S 
)

Creates a CAMsymbolicFunction of Vcount variables and Ccount symbolic constants from the initialization string S. If the construction process fails, program execution stops and an error message is output.

Sample:
//
//  Create a CAMsymbolicFunction that implements a*x^2 + b*x + c;
//  a, b, c being symbolic constants.
//
    int Vcount       = 1;                        // number of independent variables
    char*V []        = {"x"};                    // specify variable name
    int Ccount       = 3;                        // number of symbolic constants
    char*C []        = {"a","b","c"};            // specify constant names
    double Cvalues[] = {1.0, 2.0, 1.0};          // initial values of a,b,c
    char* S = "a*x^2 + b*x + c";                 // initialization string

    CAMsymbolicFunction f(V,Vcount,C,Ccount,Cvalues, S);

    cout << f << endl << endl;                    // print out function

    cout << "The value of the function at x = 1.0 is " 
         << f(1.0) << endl << endl;

    f.setConstantValue("a",2.0);                  // reset the symbolic constant
                                                  // a to have the value 2.0
    cout << f << endl << endl;                    // print out function

    cout << "The value of the function at x = 1.0 is  " 
         << f(1.0) << endl;

Definition at line 261 of file symfun.cpp.


Member Function Documentation

int CAMsymbolicFunction::initialize (  ) 

Initializes a CAMsymbolicFunction instance to a null CAMsymbolicFunction.

Definition at line 396 of file symfun.cpp.

int CAMsymbolicFunction::initialize ( char const *  S  ) 

Initialize an CAMsymbolicFunction instance to one of a single variable, x, where the function is specified by the null terminated string S. If the initialization fails, error diagnostics are output to the standard error stream (cerr) and the program returns an error value.

Returns:
0 (= no error) 1 (= error).

Definition at line 414 of file symfun.cpp.

int CAMsymbolicFunction::initialize ( const CAMsymbolicFunction F  ) 

Initializes the CAMsymbolicFunction instance with F

Definition at line 537 of file symfun.cpp.

int CAMsymbolicFunction::initialize ( const char **  V,
int  Vcount,
char const *  S 
)

Initializes a CAMsymbolicFunction instance to one of Vcount variables from the initialization string S. S is a null terminated character string. If the initialization fails, error diagnostics are output to the standard error stream (cerr) and the program returns an error value.

Returns:
0 (= no error) 1 (= error).
Sample specification and use of a function of two variables x and y:

CAMsymbolicFunction F;              // Create null instance
int Vcount = 2;                     // number of independent variables
char*V []  = {"x","y"};             // x,y  = independent variable names
char*S     = "x^2 + 2*y";           // specify a function 
     
int ierr = F.initialize(V,Vcount,S);// initialize 
if(ierr != 0) 
{
cerr << "Initialization of CAMsymbolicFunction Failed" << endl;
exit(1);
}

    
cout << F(2.0,3.0) << endl;        // evaluate and output result at (x,y) = (2.0,3.0) 

Definition at line 463 of file symfun.cpp.

int CAMsymbolicFunction::initialize ( const char **  V,
int  Vcount,
const char **  C,
int  Ccount,
double const *  Cvalues,
char const *  S 
)

Initializes a CAMsymbolicFunction instance to one of Vcount variables and Ccount symbolic constants from the initialization string S. If the initialization fails, error diagnostics are output to the standard error stream (cerr) and the program returns an error value.

Sample:
//
//  Initializes a CAMsymbolic function instance to one that implements
//  a*x^2 + b*x + c; a, b, c being symbolic constants.
//
    CAMsymbolicFunction f;                       // create instance
     
    int Vcount       = 1;                        // number of independent variables
    char*V []        = {"x"};                    // specify variable name
    int Ccount       = 3;                        // number of symbolic constants
    char*C []        = {"a","b","c"};            // specify constant names
    double Cvalues[] = {1.0, 2.0, 1.0};          // initial values of a,b,c
    char* S = "a*x^2 + b*x + c";                 // initialization string

    int ierr = f.initialize(V,Vcount,C,Ccount,Cvalues, S);
    if(ierr != 0) 
    {
    cerr << "Initialization of CAMsymbolicFunction Failed" << endl;
    exit(1);
    }

    cout << f << endl << endl;                    // print out function

    cout << "The value of the function at x = 1.0 is " 
         << f(1.0) << endl << endl;

    f.setConstantValue("a",2.0);                  // reset the symbolic constant
                                                  // a to have the value 2.0
    cout << f << endl << endl;                    // print out function

    cout << "The value of the function at x = 1.0 is  " 
         << f(1.0) << endl;

Definition at line 523 of file symfun.cpp.

void CAMsymbolicFunction::operator= ( const CAMsymbolicFunction F  ) 

Assignment operator. The instance is intialized using F. The data associated with the original instance is destroyed.

Definition at line 610 of file symfun.cpp.

char * CAMsymbolicFunction::getConstructorString (  )  const

Returns the string used to initialize the CAMsymbolicFunction.

Definition at line 659 of file symfun.cpp.

int CAMsymbolicFunction::getVariableCount (  )  const

Returns the number of variables associated with the CAMsymbolicFunction.

Definition at line 666 of file symfun.cpp.

char * CAMsymbolicFunction::getVariableName ( int  i  )  const

Returns the name of the ith variable associated with the CAMsymbolicFunction.

Definition at line 675 of file symfun.cpp.

int CAMsymbolicFunction::getConstantCount (  )  const

Returns the number of symbolic constants associated with the CAMsymbolicFunction.

Definition at line 683 of file symfun.cpp.

char * CAMsymbolicFunction::getConstantName ( int  i  )  const

Returns the name of the ith symbolic constant associated with the CAMsymbolicFunction.

Definition at line 691 of file symfun.cpp.

double CAMsymbolicFunction::getConstantValue ( int  i  )  const

Returns the value of the ith symbolic constant associated with the CAMsymbolicFunction.

Definition at line 699 of file symfun.cpp.

void CAMsymbolicFunction::setConstantValue ( char *  S,
double  x 
)

Returns the value of the ith symbolic constant associated with the CAMsymbolicFunction.

Definition at line 710 of file symfun.cpp.

double CAMsymbolicFunction::operator() ( double  x  ) 

Returns the value of the CAMsymbolicFunction using the variable value x.

Definition at line 773 of file symfun.cpp.

double CAMsymbolicFunction::operator() ( double  x1,
double  x2 
)

Returns the value of the CAMsymbolicFunction using the variable value (x1,x2).

Definition at line 784 of file symfun.cpp.

double CAMsymbolicFunction::operator() ( double  x1,
double  x2,
double  x3 
)

Returns the value of the CAMsymbolicFunction using the variable value (x1,x2,x3).

Definition at line 799 of file symfun.cpp.

double CAMsymbolicFunction::operator() ( double  x1,
double  x2,
double  x3,
double  x4 
)

Returns the value of the CAMsymbolicFunction using the variable value (x1,x2,x3,x4).

Definition at line 814 of file symfun.cpp.

double CAMsymbolicFunction::operator() ( double *  x,
int  n 
)

Returns the value of the CAMsymbolicFunction using the n variable values in the double array x.

Definition at line 830 of file symfun.cpp.


Friends And Related Function Documentation

__IMPEXP__ friend ostream& operator<< ( ostream &  out_stream,
const CAMsymbolicFunction F 
) [friend]

Outputs the initialization string, the variable names, the symbolic constant names and the symbolic constant values.

Definition at line 628 of file symfun.cpp.


The documentation for this class was generated from the following files:
Generated on Wed Jan 14 09:18:14 2009 for DoubleVector by  doxygen 1.5.1-p1