package umontreal.iro.lecuyer.functions;
/**
* Represents a function computing
* (af (x) + b)p for a user-defined function
* f (x) and power p.
*
*/
public class PowerMathFunction implements MathFunction
,
MathFunctionWithFirstDerivative {
private MathFunction func;
private double a, b;
private double power;
/**
* Constructs a new power function for function func and power
* power. The values of the constants are a = 1 and b = 0.
*
* @param func the function f (x).
*
* @param power the power p.
*
*
*/
public PowerMathFunction (MathFunction func, double power) {
this (func, 1, 0, power);
}
/**
* Constructs a new power function for function func, power
* power, and constants a and b.
*
* @param func the function f (x).
*
* @param power the power p.
*
* @param a the multiplicative constant.
*
* @param b the additive constant.
*
*
*/
public PowerMathFunction (MathFunction func, double a, double b, double power) {
if (func == null)
throw new NullPointerException ();
this.func = func;
this.a = a;
this.b = b;
this.power = power;
}
/**
* Returns the function f (x).
*
* @return the function.
*
*/
public MathFunction getFunction () {
return func;
}
/**
* Returns the value of a.
*
* @return the value of a.
*
*/
public double getA () {
return a;
}
/**
* Returns the value of b.
*
* @return the value of b.
*
*/
public double getB () {
return b;
}
/**
* Returns the power p.
*
* @return the power.
*
*/
public double getPower () {
return power;
}
public double derivative (double x) {
final double fder = MathFunctionUtil.derivative (func, x);
return getA()*getPower()*Math.pow (getA() * func.evaluate (x) + getB(), getPower() - 1)*fder;
}
public double evaluate (double x) {
final double v = func.evaluate (x);
return Math.pow (a * v + b, power);
}
}
Ads help maintain this website.