commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r735545 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/analysis/integration/ site/xdoc/ test/org/apache/commons/math/analysis/integration/
Date Sun, 18 Jan 2009 21:06:15 GMT
Author: luc
Date: Sun Jan 18 13:06:15 2009
New Revision: 735545

URL: http://svn.apache.org/viewvc?rev=735545&view=rev
Log:
improved consistency between solvers/integrators
by providing the integrand function as a parameter to integrate
rather that at construction, thus allowing reuse of a configured integrator
Jira: MATH-218

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/RombergIntegrator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/SimpsonIntegrator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/TrapezoidIntegrator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegrator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/integration/RombergIntegratorTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/integration/SimpsonIntegratorTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/integration/TrapezoidIntegratorTest.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/RombergIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/RombergIntegrator.java?rev=735545&r1=735544&r2=735545&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/RombergIntegrator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/RombergIntegrator.java
Sun Jan 18 13:06:15 2009
@@ -36,21 +36,39 @@
  */
 public class RombergIntegrator extends UnivariateRealIntegratorImpl {
 
-    /** serializable version identifier */
-    private static final long serialVersionUID = -1058849527738180243L;
+    /** Serializable version identifier. */
+    private static final long serialVersionUID = 4616482344304576900L;
 
     /**
      * Construct an integrator for the given function.
      * 
      * @param f function to integrate
+     * @deprecated as of 2.0 the integrand function is passed as an argument
+     * to the {@link #integrate(UnivariateRealFunction, double, double)}method.
      */
+    @Deprecated
     public RombergIntegrator(UnivariateRealFunction f) {
         super(f, 32);
     }
 
+    /**
+     * Construct an integrator.
+     */
+    public RombergIntegrator() {
+        super(32);
+    }
+
+    /** {@inheritDoc} */
+    @Deprecated
+    public double integrate(final double min, final double max)
+        throws MaxIterationsExceededException, FunctionEvaluationException, IllegalArgumentException
{
+        return integrate(f, min, max);
+    }
+
     /** {@inheritDoc} */
-   public double integrate(double min, double max) throws MaxIterationsExceededException,
-        FunctionEvaluationException, IllegalArgumentException {
+    public double integrate(final UnivariateRealFunction f,
+                            final double min, final double max)
+        throws MaxIterationsExceededException, FunctionEvaluationException, IllegalArgumentException
{
         
         int i = 1, j, m = maximalIterationCount + 1;
         // Array structure here can be improved for better space
@@ -61,11 +79,11 @@
         verifyInterval(min, max);
         verifyIterationCount();
 
-        TrapezoidIntegrator qtrap = new TrapezoidIntegrator(this.f);
-        t[0][0] = qtrap.stage(min, max, 0);
+        TrapezoidIntegrator qtrap = new TrapezoidIntegrator();
+        t[0][0] = qtrap.stage(f, min, max, 0);
         olds = t[0][0];
         while (i <= maximalIterationCount) {
-            t[i][0] = qtrap.stage(min, max, i);
+            t[i][0] = qtrap.stage(f, min, max, i);
             for (j = 1; j <= i; j++) {
                 // Richardson extrapolation coefficient
                 r = (1L << (2 * j)) -1;

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/SimpsonIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/SimpsonIntegrator.java?rev=735545&r1=735544&r2=735545&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/SimpsonIntegrator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/SimpsonIntegrator.java
Sun Jan 18 13:06:15 2009
@@ -35,21 +35,39 @@
  */
 public class SimpsonIntegrator extends UnivariateRealIntegratorImpl {
 
-    /** serializable version identifier */
-    private static final long serialVersionUID = 3405465123320678216L;
+    /** Serializable version identifier. */
+    private static final long serialVersionUID = 2535890386567281329L;
 
     /**
      * Construct an integrator for the given function.
      * 
      * @param f function to integrate
+     * @deprecated as of 2.0 the integrand function is passed as an argument
+     * to the {@link #integrate(UnivariateRealFunction, double, double)}method.
      */
+    @Deprecated
     public SimpsonIntegrator(UnivariateRealFunction f) {
         super(f, 64);
     }
 
+    /**
+     * Construct an integrator.
+     */
+    public SimpsonIntegrator() {
+        super(64);
+    }
+
+    /** {@inheritDoc} */
+    @Deprecated
+    public double integrate(final double min, final double max)
+        throws MaxIterationsExceededException, FunctionEvaluationException, IllegalArgumentException
{
+        return integrate(f, min, max);
+    }
+
     /** {@inheritDoc} */
-    public double integrate(double min, double max) throws MaxIterationsExceededException,
-        FunctionEvaluationException, IllegalArgumentException {
+    public double integrate(final UnivariateRealFunction f,
+                            final double min, final double max)
+        throws MaxIterationsExceededException, FunctionEvaluationException, IllegalArgumentException
{
         
         int i = 1;
         double s, olds, t, oldt;
@@ -58,17 +76,17 @@
         verifyInterval(min, max);
         verifyIterationCount();
 
-        TrapezoidIntegrator qtrap = new TrapezoidIntegrator(this.f);
+        TrapezoidIntegrator qtrap = new TrapezoidIntegrator();
         if (minimalIterationCount == 1) {
-            s = (4 * qtrap.stage(min, max, 1) - qtrap.stage(min, max, 0)) / 3.0;
+            s = (4 * qtrap.stage(f, min, max, 1) - qtrap.stage(f, min, max, 0)) / 3.0;
             setResult(s, 1);
             return result;
         }
         // Simpson's rule requires at least two trapezoid stages.
         olds = 0;
-        oldt = qtrap.stage(min, max, 0);
+        oldt = qtrap.stage(f, min, max, 0);
         while (i <= maximalIterationCount) {
-            t = qtrap.stage(min, max, i);
+            t = qtrap.stage(f, min, max, i);
             s = (4 * t - oldt) / 3.0;
             if (i >= minimalIterationCount) {
                 final double delta = Math.abs(s - olds);

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/TrapezoidIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/TrapezoidIntegrator.java?rev=735545&r1=735544&r2=735545&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/TrapezoidIntegrator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/TrapezoidIntegrator.java
Sun Jan 18 13:06:15 2009
@@ -34,22 +34,32 @@
  */
 public class TrapezoidIntegrator extends UnivariateRealIntegratorImpl {
 
-    /** serializable version identifier */
-    private static final long serialVersionUID = 4978222553983172543L;
+    /** Serializable version identifier. */
+    private static final long serialVersionUID = 6963842845860399200L;
 
-    /** intermediate result */
+    /** Intermediate result. */
     private double s;
 
     /**
      * Construct an integrator for the given function.
      * 
      * @param f function to integrate
+     * @deprecated as of 2.0 the integrand function is passed as an argument
+     * to the {@link #integrate(UnivariateRealFunction, double, double)}method.
      */
+    @Deprecated
     public TrapezoidIntegrator(UnivariateRealFunction f) {
         super(f, 64);
     }
 
     /**
+     * Construct an integrator.
+     */
+    public TrapezoidIntegrator() {
+        super(64);
+    }
+
+    /**
      * Compute the n-th stage integral of trapezoid rule. This function
      * should only be called by API <code>integrate()</code> in the package.
      * To save time it does not verify arguments - caller does.
@@ -58,6 +68,7 @@
      * arbitrary m sections because this configuration can best utilize the
      * alrealy computed values.</p>
      *
+     * @param f the integrand function
      * @param min the lower bound for the interval
      * @param max the upper bound for the interval
      * @param n the stage of 1/2 refinement, n = 0 is no refinement
@@ -65,8 +76,9 @@
      * @throws FunctionEvaluationException if an error occurs evaluating the
      * function
      */
-    double stage(double min, double max, int n) throws
-        FunctionEvaluationException {
+    double stage(final UnivariateRealFunction f,
+                 final double min, final double max, final int n)
+        throws FunctionEvaluationException {
         
         long i, np;
         double x, spacing, sum = 0;
@@ -89,8 +101,16 @@
     }
 
     /** {@inheritDoc} */
-    public double integrate(double min, double max) throws MaxIterationsExceededException,
-        FunctionEvaluationException, IllegalArgumentException {
+    @Deprecated
+    public double integrate(final double min, final double max)
+        throws MaxIterationsExceededException, FunctionEvaluationException, IllegalArgumentException
{
+        return integrate(f, min, max);
+    }
+
+    /** {@inheritDoc} */
+    public double integrate(final UnivariateRealFunction f,
+                            final double min, final double max)
+        throws MaxIterationsExceededException, FunctionEvaluationException, IllegalArgumentException
{
         
         int i = 1;
         double t, oldt;
@@ -99,9 +119,9 @@
         verifyInterval(min, max);
         verifyIterationCount();
 
-        oldt = stage(min, max, 0);
+        oldt = stage(f, min, max, 0);
         while (i <= maximalIterationCount) {
-            t = stage(min, max, i);
+            t = stage(f, min, max, i);
             if (i >= minimalIterationCount) {
                 final double delta = Math.abs(t - oldt);
                 final double rLimit =

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegrator.java?rev=735545&r1=735544&r2=735545&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegrator.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegrator.java
Sun Jan 18 13:06:15 2009
@@ -19,6 +19,7 @@
 import org.apache.commons.math.ConvergenceException;
 import org.apache.commons.math.ConvergingAlgorithm;
 import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.analysis.UnivariateRealFunction;
 
 /**
  * Interface for univariate real integration algorithms.
@@ -70,11 +71,30 @@
      * function
      * @throws IllegalArgumentException if min > max or the endpoints do not
      * satisfy the requirements specified by the integrator
+     * @deprecated replaced by {@link #integrate(UnivariateRealFunction, double, double)}
+     * since 2.0
      */
+    @Deprecated
     double integrate(double min, double max) throws ConvergenceException, 
         FunctionEvaluationException, IllegalArgumentException;
 
     /**
+     * Integrate the function in the given interval.
+     * 
+     * @param min the lower bound for the interval
+     * @param max the upper bound for the interval
+     * @return the value of integral
+     * @throws ConvergenceException if the maximum iteration count is exceeded
+     * or the integrator detects convergence problems otherwise
+     * @throws FunctionEvaluationException if an error occurs evaluating the
+     * function
+     * @throws IllegalArgumentException if min > max or the endpoints do not
+     * satisfy the requirements specified by the integrator
+     */
+    double integrate(UnivariateRealFunction f, double min, double max) throws ConvergenceException,

+        FunctionEvaluationException, IllegalArgumentException;
+
+    /**
      * Get the result of the last run of the integrator.
      * 
      * @return the last result

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java?rev=735545&r1=735544&r2=735545&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java
Sun Jan 18 13:06:15 2009
@@ -44,7 +44,10 @@
     /** the last computed integral */
     protected double result;
 
-    /** the integrand function */
+    /** The integrand functione.
+     * @deprecated as of 2.0 the integrand function is passed as an argument
+     * to the {@link #integrate(UnivariateRealFunction, double, double)}method. */
+    @Deprecated
     protected UnivariateRealFunction f;
 
     /**
@@ -54,7 +57,10 @@
      * @param defaultMaximalIterationCount maximum number of iterations
      * @throws IllegalArgumentException if f is null or the iteration
      * limits are not valid
+     * @deprecated as of 2.0 the integrand function is passed as an argument
+     * to the {@link #integrate(UnivariateRealFunction, double, double)}method.
      */
+    @Deprecated
     protected UnivariateRealIntegratorImpl(final UnivariateRealFunction f,
                                            final int defaultMaximalIterationCount)
         throws IllegalArgumentException {
@@ -74,6 +80,25 @@
     }
 
     /**
+     * Construct an integrator with given iteration count and accuracy.
+     * 
+     * @param defaultMaximalIterationCount maximum number of iterations
+     * @throws IllegalArgumentException if f is null or the iteration
+     * limits are not valid
+     */
+    protected UnivariateRealIntegratorImpl(final int defaultMaximalIterationCount)
+        throws IllegalArgumentException {
+        super(defaultMaximalIterationCount, 1.0e-15);
+
+        // parameters that are problem specific
+        setRelativeAccuracy(1.0e-6);
+        this.defaultMinimalIterationCount = 3;
+        this.minimalIterationCount = defaultMinimalIterationCount;
+        
+        verifyIterationCount();
+    }
+
+    /**
      * Access the last computed integral.
      * 
      * @return the last computed integral

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=735545&r1=735544&r2=735545&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sun Jan 18 13:06:15 2009
@@ -76,9 +76,9 @@
         Added support for multi-dimensional Fourier transform.
       </action>
       <action dev="luc" type="update" issue="MATH-218" >
-        The root solvers now take the function to solve as a parameter to
-        the solve methods, thus allowing to reuse the same solver for different
-        functions.
+        The root solvers and the integrators now take the function to solve as a
+        parameter to the solve/integrate methods, thus allowing to reuse the same
+        solver/integrator for different functions.
       </action>
       <action dev="luc" type="add" issue="MATH-234" >
         Added setter methods for rows and columns in matrices.

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/integration/RombergIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/integration/RombergIntegratorTest.java?rev=735545&r1=735544&r2=735545&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/integration/RombergIntegratorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/integration/RombergIntegratorTest.java
Sun Jan 18 13:06:15 2009
@@ -39,17 +39,17 @@
      */
     public void testSinFunction() throws MathException {
         UnivariateRealFunction f = new SinFunction();
-        UnivariateRealIntegrator integrator = new RombergIntegrator(f);
+        UnivariateRealIntegrator integrator = new RombergIntegrator();
         double min, max, expected, result, tolerance;
 
         min = 0; max = Math.PI; expected = 2;
         tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
-        result = integrator.integrate(min, max);
+        result = integrator.integrate(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -Math.PI/3; max = 0; expected = -0.5;
         tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
-        result = integrator.integrate(min, max);
+        result = integrator.integrate(f, min, max);
         assertEquals(expected, result, tolerance);
     }
 
@@ -58,22 +58,22 @@
      */
     public void testQuinticFunction() throws MathException {
         UnivariateRealFunction f = new QuinticFunction();
-        UnivariateRealIntegrator integrator = new RombergIntegrator(f);
+        UnivariateRealIntegrator integrator = new RombergIntegrator();
         double min, max, expected, result, tolerance;
 
         min = 0; max = 1; expected = -1.0/48;
         tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
-        result = integrator.integrate(min, max);
+        result = integrator.integrate(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = 0; max = 0.5; expected = 11.0/768;
         tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
-        result = integrator.integrate(min, max);
+        result = integrator.integrate(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -1; max = 4; expected = 2048/3.0 - 78 + 1.0/48;
         tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
-        result = integrator.integrate(min, max);
+        result = integrator.integrate(f, min, max);
         assertEquals(expected, result, tolerance);
     }
 
@@ -82,11 +82,11 @@
      */
     public void testParameters() throws Exception {
         UnivariateRealFunction f = new SinFunction();
-        UnivariateRealIntegrator integrator = new RombergIntegrator(f);
+        UnivariateRealIntegrator integrator = new RombergIntegrator();
 
         try {
             // bad interval
-            integrator.integrate(1, -1);
+            integrator.integrate(f, 1, -1);
             fail("Expecting IllegalArgumentException - bad interval");
         } catch (IllegalArgumentException ex) {
             // expected
@@ -95,7 +95,7 @@
             // bad iteration limits
             integrator.setMinimalIterationCount(5);
             integrator.setMaximalIterationCount(4);
-            integrator.integrate(-1, 1);
+            integrator.integrate(f, -1, 1);
             fail("Expecting IllegalArgumentException - bad iteration limits");
         } catch (IllegalArgumentException ex) {
             // expected
@@ -104,7 +104,7 @@
             // bad iteration limits
             integrator.setMinimalIterationCount(10);
             integrator.setMaximalIterationCount(50);
-            integrator.integrate(-1, 1);
+            integrator.integrate(f, -1, 1);
             fail("Expecting IllegalArgumentException - bad iteration limits");
         } catch (IllegalArgumentException ex) {
             // expected

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/integration/SimpsonIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/integration/SimpsonIntegratorTest.java?rev=735545&r1=735544&r2=735545&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/integration/SimpsonIntegratorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/integration/SimpsonIntegratorTest.java
Sun Jan 18 13:06:15 2009
@@ -38,17 +38,17 @@
      */
     public void testSinFunction() throws MathException {
         UnivariateRealFunction f = new SinFunction();
-        UnivariateRealIntegrator integrator = new SimpsonIntegrator(f);
+        UnivariateRealIntegrator integrator = new SimpsonIntegrator();
         double min, max, expected, result, tolerance;
 
         min = 0; max = Math.PI; expected = 2;
         tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
-        result = integrator.integrate(min, max);
+        result = integrator.integrate(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -Math.PI/3; max = 0; expected = -0.5;
         tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
-        result = integrator.integrate(min, max);
+        result = integrator.integrate(f, min, max);
         assertEquals(expected, result, tolerance);
     }
 
@@ -57,22 +57,22 @@
      */
     public void testQuinticFunction() throws MathException {
         UnivariateRealFunction f = new QuinticFunction();
-        UnivariateRealIntegrator integrator = new SimpsonIntegrator(f);
+        UnivariateRealIntegrator integrator = new SimpsonIntegrator();
         double min, max, expected, result, tolerance;
 
         min = 0; max = 1; expected = -1.0/48;
         tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
-        result = integrator.integrate(min, max);
+        result = integrator.integrate(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = 0; max = 0.5; expected = 11.0/768;
         tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
-        result = integrator.integrate(min, max);
+        result = integrator.integrate(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -1; max = 4; expected = 2048/3.0 - 78 + 1.0/48;
         tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
-        result = integrator.integrate(min, max);
+        result = integrator.integrate(f, min, max);
         assertEquals(expected, result, tolerance);
     }
 
@@ -81,11 +81,11 @@
      */
     public void testParameters() throws Exception {
         UnivariateRealFunction f = new SinFunction();
-        UnivariateRealIntegrator integrator = new SimpsonIntegrator(f);
+        UnivariateRealIntegrator integrator = new SimpsonIntegrator();
 
         try {
             // bad interval
-            integrator.integrate(1, -1);
+            integrator.integrate(f, 1, -1);
             fail("Expecting IllegalArgumentException - bad interval");
         } catch (IllegalArgumentException ex) {
             // expected
@@ -94,7 +94,7 @@
             // bad iteration limits
             integrator.setMinimalIterationCount(5);
             integrator.setMaximalIterationCount(4);
-            integrator.integrate(-1, 1);
+            integrator.integrate(f, -1, 1);
             fail("Expecting IllegalArgumentException - bad iteration limits");
         } catch (IllegalArgumentException ex) {
             // expected
@@ -103,7 +103,7 @@
             // bad iteration limits
             integrator.setMinimalIterationCount(10);
             integrator.setMaximalIterationCount(99);
-            integrator.integrate(-1, 1);
+            integrator.integrate(f, -1, 1);
             fail("Expecting IllegalArgumentException - bad iteration limits");
         } catch (IllegalArgumentException ex) {
             // expected

Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/integration/TrapezoidIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/integration/TrapezoidIntegratorTest.java?rev=735545&r1=735544&r2=735545&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/integration/TrapezoidIntegratorTest.java
(original)
+++ commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/integration/TrapezoidIntegratorTest.java
Sun Jan 18 13:06:15 2009
@@ -38,17 +38,17 @@
      */
     public void testSinFunction() throws MathException {
         UnivariateRealFunction f = new SinFunction();
-        UnivariateRealIntegrator integrator = new TrapezoidIntegrator(f);
+        UnivariateRealIntegrator integrator = new TrapezoidIntegrator();
         double min, max, expected, result, tolerance;
 
         min = 0; max = Math.PI; expected = 2;
         tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
-        result = integrator.integrate(min, max);
+        result = integrator.integrate(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -Math.PI/3; max = 0; expected = -0.5;
         tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
-        result = integrator.integrate(min, max);
+        result = integrator.integrate(f, min, max);
         assertEquals(expected, result, tolerance);
     }
 
@@ -57,22 +57,22 @@
      */
     public void testQuinticFunction() throws MathException {
         UnivariateRealFunction f = new QuinticFunction();
-        UnivariateRealIntegrator integrator = new TrapezoidIntegrator(f);
+        UnivariateRealIntegrator integrator = new TrapezoidIntegrator();
         double min, max, expected, result, tolerance;
 
         min = 0; max = 1; expected = -1.0/48;
         tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
-        result = integrator.integrate(min, max);
+        result = integrator.integrate(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = 0; max = 0.5; expected = 11.0/768;
         tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
-        result = integrator.integrate(min, max);
+        result = integrator.integrate(f, min, max);
         assertEquals(expected, result, tolerance);
 
         min = -1; max = 4; expected = 2048/3.0 - 78 + 1.0/48;
         tolerance = Math.abs(expected * integrator.getRelativeAccuracy());
-        result = integrator.integrate(min, max);
+        result = integrator.integrate(f, min, max);
         assertEquals(expected, result, tolerance);
     }
 
@@ -81,11 +81,11 @@
      */
     public void testParameters() throws Exception {
         UnivariateRealFunction f = new SinFunction();
-        UnivariateRealIntegrator integrator = new TrapezoidIntegrator(f);
+        UnivariateRealIntegrator integrator = new TrapezoidIntegrator();
 
         try {
             // bad interval
-            integrator.integrate(1, -1);
+            integrator.integrate(f, 1, -1);
             fail("Expecting IllegalArgumentException - bad interval");
         } catch (IllegalArgumentException ex) {
             // expected
@@ -94,7 +94,7 @@
             // bad iteration limits
             integrator.setMinimalIterationCount(5);
             integrator.setMaximalIterationCount(4);
-            integrator.integrate(-1, 1);
+            integrator.integrate(f, -1, 1);
             fail("Expecting IllegalArgumentException - bad iteration limits");
         } catch (IllegalArgumentException ex) {
             // expected
@@ -103,7 +103,7 @@
             // bad iteration limits
             integrator.setMinimalIterationCount(10);
             integrator.setMaximalIterationCount(99);
-            integrator.integrate(-1, 1);
+            integrator.integrate(f, -1, 1);
             fail("Expecting IllegalArgumentException - bad iteration limits");
         } catch (IllegalArgumentException ex) {
             // expected



Mime
View raw message