From db0ad53076bb83793c8ead5bf6e003e5625689d7 Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Tue, 27 Aug 2013 11:15:50 +0000 Subject: [PATCH] Added a convenience createConstant method for DerivativeStructure. Thanks to Ajo Fod. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1517789 13f79535-47bb-0310-9956-ffa450edef68 --- .../differentiation/DerivativeStructure.java | 14 ++++++++++++++ .../differentiation/DerivativeStructureTest.java | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructure.java b/src/main/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructure.java index 3a90a4def..bb29eee9e 100644 --- a/src/main/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructure.java +++ b/src/main/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructure.java @@ -232,6 +232,20 @@ public class DerivativeStructure implements RealFieldElement + * This method is a convenience factory method, it simply calls + * {@code new DerivativeStructure(getFreeParameters(), getOrder(), c)} + *

+ * @param c value of the constant + * @return a constant compatible with instance order and number of parameters + * @see #DerivativeStructure(int, int, double) + * @since 3.3 + */ + public DerivativeStructure createConstant(final double c) { + return new DerivativeStructure(getFreeParameters(), getOrder(), c); + } + /** {@inheritDoc} * @since 3.2 */ diff --git a/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java b/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java index 4d1f3b9cf..4aa0660dd 100644 --- a/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java +++ b/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java @@ -89,6 +89,15 @@ public class DerivativeStructureTest extends ExtendedFieldElementAbstractTest