2D functions

Header file function2d.h

Generic 2D function class `Function2d'

A template class, generated on the classes of the argument and the result. Functions of this class take two arguments of the argument type and return a single value of the result type. Subclasses must provide identification, data, input/output and evaluation. Inherits from `Classio'.

Example:

#include<function2d.h>
...
class my_function: public Function2d<double,double>
{
   public:

   // data
   double mx,my,c;

   // input and output
   void Read(istream& stream) { stream >> mx >> my >> c; }
   void Write(ostream& stream) const { stream << mx << ' ' << my << ' ' << c; }

   // evaluation
   double evaluate(const double& x, const double& y)
   { return mx * x + my * y + c; }
};

The method `()' is defined to evaluate the function, e.g.

my_function f1; cin >> f1; // read parameters
double x,y; cin >> x >> y; // read argument
double f = f1(x,y); cout << f << endl; // evaluate function

Real 2D function class `Realfunction2d'

Inherits from Function2d<double,double&ht;

A generic write-with-switch is provided for writing pointered polymorphic subclasses. The corresponding read-with-switch is provided for groups of functions in the library.

Product of two 1D functions: Realfunction2d_1dproduct

Data is a pair of Realfunction1d.
#include<function2d.h>
...
Realfunction2d_1dproduct p; cin >> p;
double x,y; cin >> x >> y;
double f = p(x,y); cout << f << endl;

Interpolated array of functions of second argument: Realfunction2d_1dinterp_1

Data is an array of pairs of values of the first argument and functions of the second argument (Realfunction1d) to use at that value. The result is interpolated between the nearest pair of functions.

Interpolated array of functions of first argument: Realfunction2d_1dinterp_2

Data is an array of pairs of values of the second argument and functions of the first argument (Realfunction1d) to use at that value. The result is interpolated between the nearest pair of functions.

2D table: Realfunction2d_table

Data is an array of pairs of doubles modelling f(x) as piecewise linear. The function evaluated is the linear interpolation (or extrapolation).

Data

nx ny	(dimensions of table)
For each x:
   xi   (x-ordinates)
For each y:
   yj   (y-ordinates)
For each x:
   For each y:
      fi,j   (function values)

Example

#include<function2d.h>
...
Realfunction2d_table t; cin >> t;
double x,y; cin >> x >> y;
double f = t(x,y); cout << f << endl; // evaluate function

2D table with polynomial interpolation: Realfunction2d_table_bipoly

Data is an array of pairs of doubles modelling f(x) as piecewise polynomial. The function evaluated is the polynomial interpolation (or extrapolation). (The inverse interpolation is still linear.)

Data

As `Realfunction2d_table', plus
xorder yorder (order of polynomials used to interpolate in x and y)
xfirst (1/0 for interpolation in x first/second)

Sum: Realfunction2d_sum

A set of 2D functions {fi}. The function returned is the sum of each fi. Data:
number_of_functions
For each:
   fi
Each fi is a Realfunction2d.

Displaced function: Realfunction2d_offset

A function f and an offset x0 y0 to its argument, the displaced function being f(x-x0,y-y0). Data:
x0 y0 f
f is a Realfunction2d.

Mapped function: Realfunction2d_map

A 2D function f and 1D functions xmap, ymap and fmap such that the function returned is fmap{f[xmap(x),ymap(y)]}. This is a fairly general form, but is particularly useful for changing units or scalings. Data:
xmap ymap fmap
f
xmap, ymap and fmap are Realfunction1ds. f is a Realfunction2d.