Function
From Open Ideas
Contents |
Definition
For a definition see MathWorld:Function
Codebook
Construction
Functions on a 1-dimensional domain
IDoubleFunction1D function10 = new DoubleFunction1D() {
public double apply(double x) {
double a = Math.sin(x);
return a * a;
}
public boolean isInDomain(double x) {
return true;
}
};
cern.jet.math.Functions f = cern.jet.math.Functions.functions; IDoubleFunction1D function11 = DoubleFunction1D.create(f.chain(f.square, f.sin));
Functions on a 2-dimensional domain
IDoubleFunction2D function20 = new DoubleFunction2D() {
public double apply(double x, double y) {
return x * y;
}
public boolean isInDomain(double x, double y) {
return y > 0.0;
}
};
Functions on a N-dimensional domain
The instantiation of n-dimensional functions is slightly different, since you have to pass the dimension on creation.
IDoubleFunctionND function30 = new DoubleFunction(3) {
public double apply(double... x) {
return x[0] + x[1] * Math.exp(x[2]);
}
public double isInDomain(double... x) {
return true;
}
};
Methods
The domain can be restricted after a function has been created. You can use an instance of a domain interface to specify on which elements the function is defined.
IDoubleDomain1D nonnegative = new DoubleInterval1D(0.0, Double.POSITIVE_INFINITY); // since DoubleInterval implements the IDoubleDomain interface function1.setDomain(nonnegative);
