Added "derivative".

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1184933 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2011-10-16 21:04:19 +00:00
parent f258ecdf91
commit 9092e81cae
21 changed files with 229 additions and 26 deletions

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,9 +27,19 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Acos implements UnivariateRealFunction { public class Acos implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return FastMath.acos(x); return FastMath.acos(x);
} }
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
/** {@inheritDoc} */
public double value(double x) {
return -1 / FastMath.sqrt(1 - x * x);
}
};
}
} }

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,9 +27,19 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Acosh implements UnivariateRealFunction { public class Acosh implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return FastMath.acosh(x); return FastMath.acosh(x);
} }
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
/** {@inheritDoc} */
public double value(double x) {
return 1 / FastMath.sqrt(x * x - 1);
}
};
}
} }

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,9 +27,19 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Asin implements UnivariateRealFunction { public class Asin implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return FastMath.asin(x); return FastMath.asin(x);
} }
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
/** {@inheritDoc} */
public double value(double x) {
return 1 / FastMath.sqrt(1 - x * x);
}
};
}
} }

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,9 +27,19 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Asinh implements UnivariateRealFunction { public class Asinh implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return FastMath.asinh(x); return FastMath.asinh(x);
} }
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
/** {@inheritDoc} */
public double value(double x) {
return 1 / FastMath.sqrt(1 + x * x);
}
};
}
} }

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,9 +27,19 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Atan implements UnivariateRealFunction { public class Atan implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return FastMath.atan(x); return FastMath.atan(x);
} }
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
/** {@inheritDoc} */
public double value(double x) {
return 1 / (1 + x * x);
}
};
}
} }

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,9 +27,19 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Atanh implements UnivariateRealFunction { public class Atanh implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return FastMath.atanh(x); return FastMath.atanh(x);
} }
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
/** {@inheritDoc} */
public double value(double x) {
return 1 / (1 - x * x);
}
};
}
} }

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,9 +27,19 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Cbrt implements UnivariateRealFunction { public class Cbrt implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return FastMath.cbrt(x); return FastMath.cbrt(x);
} }
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
/** {@inheritDoc} */
public double value(double x) {
return 1 / (3 * FastMath.cbrt(x * x));
}
};
}
} }

View File

@ -17,7 +17,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
/** /**
* Constant function. * Constant function.
@ -25,7 +25,7 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Constant implements UnivariateRealFunction { public class Constant implements DifferentiableUnivariateRealFunction {
/** Constant. */ /** Constant. */
private final double c; private final double c;
@ -40,4 +40,9 @@ public class Constant implements UnivariateRealFunction {
public double value(double x) { public double value(double x) {
return c; return c;
} }
/** {@inheritDoc} */
public DifferentiableUnivariateRealFunction derivative() {
return new Constant(0);
}
} }

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,9 +27,19 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Cos implements UnivariateRealFunction { public class Cos implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return FastMath.cos(x); return FastMath.cos(x);
} }
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
/** {@inheritDoc} */
public double value(double x) {
return -FastMath.sin(x);
}
};
}
} }

View File

@ -17,7 +17,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,9 +26,14 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Cosh implements UnivariateRealFunction { public class Cosh implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return FastMath.cosh(x); return FastMath.cosh(x);
} }
/** {@inheritDoc} */
public DifferentiableUnivariateRealFunction derivative() {
return new Sinh();
}
} }

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,9 +27,19 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Exp implements UnivariateRealFunction { public class Exp implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return FastMath.exp(x); return FastMath.exp(x);
} }
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
/** {@inheritDoc} */
public double value(double x) {
return FastMath.exp(x);
}
};
}
} }

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,9 +27,19 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Expm1 implements UnivariateRealFunction { public class Expm1 implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return FastMath.expm1(x); return FastMath.expm1(x);
} }
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
/** {@inheritDoc} */
public double value(double x) {
return FastMath.exp(x);
}
};
}
} }

View File

@ -17,7 +17,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
/** /**
* Identity function. * Identity function.
@ -25,9 +25,14 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Identity implements UnivariateRealFunction { public class Identity implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return x; return x;
} }
/** {@inheritDoc} */
public DifferentiableUnivariateRealFunction derivative() {
return new Constant(1);
}
} }

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
/** /**
* Inverse function. * Inverse function.
@ -25,9 +26,19 @@ import org.apache.commons.math.analysis.UnivariateRealFunction;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Inverse implements UnivariateRealFunction { public class Inverse implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return 1 / x; return 1 / x;
} }
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
/** {@inheritDoc} */
public double value(double x) {
return -1 / (x * x);
}
};
}
} }

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,9 +27,19 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Log implements UnivariateRealFunction { public class Log implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return FastMath.log(x); return FastMath.log(x);
} }
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
/** {@inheritDoc} */
public double value(double x) {
return 1 / x;
}
};
}
} }

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,9 +27,19 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Log1p implements UnivariateRealFunction { public class Log1p implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return FastMath.log1p(x); return FastMath.log1p(x);
} }
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
/** {@inheritDoc} */
public double value(double x) {
return 1 / (1 + x);
}
};
}
} }

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,7 +27,7 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Power implements UnivariateRealFunction { public class Power implements DifferentiableUnivariateRealFunction {
/** Power. */ /** Power. */
private final double p; private final double p;
@ -41,4 +42,14 @@ public class Power implements UnivariateRealFunction {
public double value(double x) { public double value(double x) {
return FastMath.pow(x, p); return FastMath.pow(x, p);
} }
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
/** {@inheritDoc} */
public double value(double x) {
return p * FastMath.pow(x, p - 1);
}
};
}
} }

View File

@ -17,7 +17,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,9 +26,14 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Sin implements UnivariateRealFunction { public class Sin implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return FastMath.sin(x); return FastMath.sin(x);
} }
/** {@inheritDoc} */
public DifferentiableUnivariateRealFunction derivative() {
return new Cos();
}
} }

View File

@ -17,7 +17,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,9 +26,14 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Sinh implements UnivariateRealFunction { public class Sinh implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return FastMath.sinh(x); return FastMath.sinh(x);
} }
/** {@inheritDoc} */
public DifferentiableUnivariateRealFunction derivative() {
return new Cosh();
}
} }

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,9 +27,20 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Tan implements UnivariateRealFunction { public class Tan implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return FastMath.tan(x); return FastMath.tan(x);
} }
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
/** {@inheritDoc} */
public double value(double x) {
final double tanX = FastMath.tan(x);
return 1 + tanX * tanX;
}
};
}
} }

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.analysis.function; package org.apache.commons.math.analysis.function;
import org.apache.commons.math.analysis.UnivariateRealFunction; import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
import org.apache.commons.math.util.FastMath; import org.apache.commons.math.util.FastMath;
/** /**
@ -26,9 +27,20 @@ import org.apache.commons.math.util.FastMath;
* @version $Id$ * @version $Id$
* @since 3.0 * @since 3.0
*/ */
public class Tanh implements UnivariateRealFunction { public class Tanh implements DifferentiableUnivariateRealFunction {
/** {@inheritDoc} */ /** {@inheritDoc} */
public double value(double x) { public double value(double x) {
return FastMath.tanh(x); return FastMath.tanh(x);
} }
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
/** {@inheritDoc} */
public double value(double x) {
final double tanhX = FastMath.tanh(x);
return 1 - tanhX * tanhX;
}
};
}
} }