Example:
#include<function.h> ... class my_function: public Function<double,double> { public: // data double m,c; // input and output void Read(istream& stream) { stream >> m >> c; } void Write(ostream& stream) const { stream << m << ' ' << c; } // evaluation double evaluate(const double& x) { return m * x + c; } };
The method `()' is defined to evaluate the function, e.g.
my_function f1; cin >> f1; // read parameters double x; cin >> x; // read argument double y = f1(x); cout << y << endl; // evaluate function
Function<double,double>
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. To use, define a pointer to an instance of the appropriate class. Data in an input stream must first specify the class identifier (the name, with lowercase first character) then the data. When writing to an output stream, the identifier is written followed by the data. Example:
#include<function.h> int main() { Realfunction1d *f; cin >> f; double x; cin >> x; cout << "f(x) = " << (*f)(x) << endl; }
Artificial example: (one would tend to use `double'; this subclass is provided for use with polymorphic functions)
#include<function.h> ... Constant p; cin >> p; double x; cin >> x; double y = p(x); cout << y << endl;
Example:
#include<function.h> ... Polynomial p; cin >> p; double x; cin >> x; double y = p(x); cout << y << endl;
Vector v; cin >> v; Polynomial p = v;
Polynomial p; cin >> p; Polynomial dp = p.differentiate();
Polynomial p; cin >> p; Polynomial dp = p.integrate();(the constant coefficient is set to zero)
Example:
#include<function.h> ... Gaussian g; cin >> m; double x; cin >> x; double y = g(x); cout << y << endl;
Example:
#include<function.h> ... Monomial m; cin >> m; double x; cin >> x; double y = m(x); cout << y << endl;
Example:
#include<function.h> ... General_polynomial p; cin >> p; double x; cin >> x; double y = p(x); cout << y << endl;
number_of_points For each: xi fi
#include<function.h> ... Table1d t; cin >> t; double x; cin >> x; double y = t(x); cout << y << endl; // evaluate function ... int n; cin >> n; Array<double> tn = t[n]; // tn should be returned with 2 elements
number_of_points For each: xi fi order
Realfunction1d
s.
The function evaluated is the sum of the constituent functions.
Realfunction1d
s.
The function evaluated is the product of the constituent functions.
Realfunction1d
s.
The function evaluated is the nest of the constituent functions,
i.e. f1(f2(...(fn(x))...)).
f0 default function number_of_ranged_functions For each: x1 x2 f range (min, max x) and function
f0
and each f
are Realfunction1d
s.
number_of__functions For each: x0 fEach
f
is a Realfunction1d
.
x0 f
f
is a Realfunction1d
.
exp, ln, log10,sin, cos, tan, sinh, cosh, tanh
.
double mod(const double a, const double b)returns a mod b, i.e. a - int(a/b) * b