NeuroLab
Function Class Reference

Class for mathematical functions. More...

Inheritance diagram for Function:

Public Member Functions

 Function (const Function &)
 Copy.
 
 Function (double d)
 Double to Function. More...
 
virtual ~Function ()
 Destructor.
 
virtual string getName () const
 Returns the name. More...
 
FunctionsetVerbose (bool verbose=true, ostream *log=&cout)
 Set function to be verbose. More...
 
virtual double getValue () const
 Returns the value. More...
 
double operator() (double x)
 Returns the value at a point. More...
 
double operator() (double x, double y)
 Returns the value at a point. More...
 
void setXInput (double)
 Set x input. More...
 
void setYInput (double)
 Set y input. More...
 
double getXInput ()
 Get x input. More...
 
double getYInput ()
 Get y input. More...
 
virtual double getLastValue () const
 Returns the value. More...
 
FunctionsetPhysical (string s, Unit u)
 Returns the function graph. More...
 
virtual FunctionsetXRange (double min, double max, double stepsize)
 Set the x range. More...
 
virtual FunctionsetYRange (double min, double max, double stepsize)
 Set the y range. More...
 
string getXInputName ()
 Get input name. More...
 
string getYInputName ()
 Get input name. More...
 
FunctionsetName (string s)
 Sets the name. More...
 
void operator+= (Function &function)
 Add. More...
 
void operator-= (Function &function)
 Subtract. More...
 
void operator*= (Function &function)
 Multiply. More...
 
void operator/= (Function &function)
 Divide. More...
 
- Public Member Functions inherited from Physical
 Physical ()
 Construct.
 
 Physical (const Physical &)
 Copy.
 
 Physical (string name)
 Construct.
 
 Physical (string name, string unitPrefix, string unitSymbol)
 Construct.
 
 Physical (string name, Unit unit)
 Construct.
 
virtual string getDescription ()
 Retrive the physical name. More...
 
virtual string getPhysicalDescription ()
 Returns the physical description. More...
 
virtual string getUnitName ()
 Returns the unit name.
 
virtual string getUnitSymbol ()
 Returns the unit name.
 
virtual void setDescription (string name)
 Set the name. More...
 
virtual void setPhysicalDescription (string name)
 Set the name. Same as setDescription(). More...
 
virtual void setUnit (Unit u)
 Set the unit.
 
virtual void setUnitPrefix (int n)
 Set unit prefix. More...
 
virtual Unit getUnit () const
 Retrieve the unit.
 

Protected Member Functions

 Function ()
 Default Constructor. More...
 
void unvalidate ()
 Set unvalid. More...
 

Protected Attributes

int nRefs
 we do reference counting
 
vector< Function * > vParents
 parents, for ref counting
 

Friends

Functionoperator/ (Function &left, Function &right)
 Divide. More...
 
Functionexp (Function &right)
 Exponential. More...
 
Functionln (Function &right)
 Logarithm. More...
 
Functionsin (Function &right)
 Sine. More...
 
Functioncos (Function &right)
 Cosine. More...
 
Functionsqrt (Function &right)
 Square root. More...
 
Functionsquare (Function &right)
 Square. More...
 
Functionroot (Function &left, Function &n)
 Root. More...
 
Functionpower (Function &left, Function &n)
 Power. More...
 
Functionintegral (Function &integrand, Function &integrator)
 Integral.. More...
 
Functionincrements (Function &right)
 Increments. More...
 
Functiongreater (Function &left, Function &right)
 Comparison. More...
 
Functionsmaller (Function &left, Function &right)
 Comparison. More...
 
Functionoperator> (Function &left, Function &right)
 Comparison. More...
 
Functionoperator< (Function &left, Function &right)
 Comparison. More...
 
Functionoperator<= (Function &left, Function &right)
 Comparison. More...
 
Functionoperator>= (Function &left, Function &right)
 Comparison. More...
 
Functionsign (Function &right)
 Sign of a number.
 
ostream & operator<< (ostream &os, Function &f)
 Appends the function specification string to a stream. More...
 
Functioninput (string)
 Create input. More...
 
Functioncnst (double)
 Create a function from a constant.
 
Functioncnst (double, string)
 Create a function from a constant and a name.
 
Functionxtable (Matrix &, Function &right)
 Create a function from a matrix.
 
Functionempty ()
 An empty function.
 

Detailed Description

Class for mathematical functions.

This class implements mathematical functions for use with the Display class (which supports only gnuplot output at the moment. Functions are created from Variables using +, -, *, /, exp, ln, sqrt, square, sqrt, power, or root. Note the special variables X and Y. Functions use referencing, and form an execution tree. When any variable in the function changes, the function output changes. Appending a function to a Display (using <<) will append the output with the current variable setting. That way you can append the same function to the same display, with different values of its variables, and the result will be different curves on top of each other. The function can be appended to any string using the << operator.

Constructor & Destructor Documentation

Function::Function ( )
inlineprotected

Default Constructor.

Constructs an empty function. This is mainly for use in the derived classes X and Y.

Function::Function ( double  d)

Double to Function.

Constructs a constant from a double. Same as cnst(double).

Member Function Documentation

virtual double Function::getLastValue ( ) const
virtual

Returns the value.

Returns the last value of the function. This is the value which was produced by the last getValue() call. No recomputation is executed.

virtual string Function::getName ( ) const
virtual

Returns the name.

Returns
The name of the Function. This is the string which has been set with setName(), and which will appear as a gnuplot lable when this function is appended to a gnuplot display.
virtual double Function::getValue ( ) const
virtual

Returns the value.

Computes the current value of the function. This is dependent on variables and input.

double Function::getXInput ( )

Get x input.

This gets the x input of the whole tree. If input values are different at different branches, the first which is encountered will be returned.

string Function::getXInputName ( )

Get input name.

Returns the name of the first input, for instance 't' or 'x'.

double Function::getYInput ( )

Get y input.

This gets the y input of the whole tree. If input values are different at different branches, the first which is encountered will be returned.

string Function::getYInputName ( )

Get input name.

Returns the name of the second input, for instance 't' or 'x'.

double Function::operator() ( double  x)
inline

Returns the value at a point.

Computes the current value of the function. This is dependent on variables and input.

double Function::operator() ( double  x,
double  y 
)
inline

Returns the value at a point.

Computes the current value of the function. This is dependent on variables and input.

void Function::operator*= ( Function function)

Multiply.

Multiplies the given function to this function object.

void Function::operator+= ( Function function)

Add.

Adds the given function to this function object.

void Function::operator-= ( Function function)

Subtract.

Subtracts the given function from the object..

void Function::operator/= ( Function function)

Divide.

Divides the given function to this function object.

Function& Function::setName ( string  s)

Sets the name.

This function returns a reference to its object for convenience.

Function& Function::setPhysical ( string  s,
Unit  u 
)

Returns the function graph.

Returns the function graph. This is dependent on variables and input range. Sets the physical type. This sets a physical name (like 'voltage'), and a unit (like mV).

Function& Function::setVerbose ( bool  verbose = true,
ostream *  log = &cout 
)

Set function to be verbose.

If this is set, the function will append its current value and its name to a stream, each time getValue() is called. setVerbose() will set all subfunctions to be verbose as well. This way a log of the whole calculation will be appended to a stream.

Parameters
verbosewhether the function is verbose (sends state log-messages to a stream)
logthe stream receiving the log messages
void Function::setXInput ( double  )

Set x input.

This sets the x input of the whole tree to the given value.

virtual Function& Function::setXRange ( double  min,
double  max,
double  stepsize 
)
virtual

Set the x range.

Sets the x range of the function, i.e. the function will be plotted in a range from minimum to maximum, with the given step size.

Parameters
minminimum
maxmaximum
stepsizestep size
void Function::setYInput ( double  )

Set y input.

This sets the y input of the whole tree to the given value.

virtual Function& Function::setYRange ( double  min,
double  max,
double  stepsize 
)
virtual

Set the y range.

Sets the y range of the function, i.e. the function will be plotted in a range from minimum to maximum, with the given step size.

Parameters
minminimum
maxmaximum
stepsizestep size
void Function::unvalidate ( )
protected

Set unvalid.

After this, the function will perform a full computation, if getValue() is called. Otherwise just the last value is return. This function needs to be called if some input has changed lower down in the execution tree.

Friends And Related Function Documentation

Function& cos ( Function right)
friend

Cosine.

Creates a Function which is the logarithm of the input function.

Function& exp ( Function right)
friend

Exponential.

Creates a Function which is the exponential of the input function.

Function& greater ( Function left,
Function right 
)
friend

Comparison.

Returns 1.0 at places where the comparison is true, and 0.0 at places where the comparison is false.

Function& increments ( Function right)
friend

Increments.

Creates the differential df(x) of a given integrand f(x). If plotted, you will see the function

\[ \mbox{Function(t)} = d f(x) \]

.

Function& input ( string  )
friend

Create input.

Creates a function which serves as input for other functions.

Function& integral ( Function integrand,
Function integrator 
)
friend

Integral..

Creates the undefinite integral of the given integrand. If plotted, you will see the function

\[ \mbox{Function(t)} = \int_0^t f(x) dx\]

.

Function& ln ( Function right)
friend

Logarithm.

Creates a Function which is the logarithm of the input function.

Function& operator/ ( Function left,
Function right 
)
friend

Divide.

Creates a Function which is the quotient of the two input functions.

Function& operator< ( Function left,
Function right 
)
friend

Comparison.

Returns 1.0 at places where the comparison is true, and 0.0 at places where the comparison is false.

ostream& operator<< ( ostream &  os,
Function f 
)
friend

Appends the function specification string to a stream.

The appended string is gnuplot readable, and may contain lots of parentheses, depending on the complexity of the function.

Function& operator<= ( Function left,
Function right 
)
friend

Comparison.

Returns 1.0 at places where the comparison is true, and 0.0 at places where the comparison is false.

Function& operator> ( Function left,
Function right 
)
friend

Comparison.

Returns 1.0 at places where the comparison is true, and 0.0 at places where the comparison is false.

Function& operator>= ( Function left,
Function right 
)
friend

Comparison.

Returns 1.0 at places where the comparison is true, and 0.0 at places where the comparison is false.

Function& power ( Function left,
Function n 
)
friend

Power.

Returns
A Function which is the nth power of the input.
Function& root ( Function left,
Function n 
)
friend

Root.

Returns
A Function which is the nth root of the input..
Function& sin ( Function right)
friend

Sine.

Creates a Function which is the logarithm of the input function.

Function& smaller ( Function left,
Function right 
)
friend

Comparison.

Returns 1.0 at places where the comparison is true, and 0.0 at places where the comparison is false.

Function& sqrt ( Function right)
friend

Square root.

Creates a Function which is the sqare root of the input function.

Function& square ( Function right)
friend

Square.

Creates a Function which is the sqare of the input function.