commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r670569 - in /commons/proper/math/branches/MATH_2_0/src: java/org/apache/commons/math/analysis/ java/org/apache/commons/math/transform/ site/xdoc/ test/org/apache/commons/math/analysis/
Date Mon, 23 Jun 2008 13:46:46 GMT
Author: luc
Date: Mon Jun 23 06:46:46 2008
New Revision: 670569

URL: http://svn.apache.org/viewvc?rev=670569&view=rev
Log:
ported all changes from trunk between r6152100 (branch 2.0 creation) and r670469 (today)
These changes contain fixes for MATH-204 and MATH-205

Modified:
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/analysis/BrentSolver.java
    commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/transform/FastCosineTransformer.java
    commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml
    commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/analysis/BrentSolverTest.java

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/analysis/BrentSolver.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/analysis/BrentSolver.java?rev=670569&r1=670568&r2=670569&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/analysis/BrentSolver.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/analysis/BrentSolver.java
Mon Jun 23 06:46:46 2008
@@ -26,7 +26,7 @@
  * <p>
  * The function should be continuous but not necessarily smooth.</p>
  *  
- * @version $Revision$ $Date$
+ * @version $Revision:670469 $ $Date:2008-06-23 10:01:38 +0200 (lun., 23 juin 2008) $
  */
 public class BrentSolver extends UnivariateRealSolverImpl {
     
@@ -128,20 +128,41 @@
         clearResult();
         verifyInterval(min, max);
         
+        double ret = Double.NaN;
+        
         double yMin = f.value(min);
         double yMax = f.value(max);
         
         // Verify bracketing
-        if (yMin * yMax >= 0) {
-            throw new IllegalArgumentException
-            ("Function values at endpoints do not have different signs." +
-                    "  Endpoints: [" + min + "," + max + "]" + 
-                    "  Values: [" + yMin + "," + yMax + "]");       
+        double sign = yMin * yMax;
+        if (sign > 0) {
+            // check if either value is close to a zero
+            if (Math.abs(yMin) <= functionValueAccuracy) {
+                setResult(min, 0);
+                ret = min;
+            } else if (Math.abs(yMax) <= functionValueAccuracy) {
+                setResult(max, 0);
+                ret = max;
+            } else {
+                // neither value is close to zero and min and max do not bracket root.
+                throw new IllegalArgumentException
+                ("Function values at endpoints do not have different signs." +
+                        "  Endpoints: [" + min + "," + max + "]" + 
+                        "  Values: [" + yMin + "," + yMax + "]");
+            }
+        } else if (sign < 0){
+            // solve using only the first endpoint as initial guess
+            ret = solve(min, yMin, max, yMax, min, yMin);
+        } else {
+            // either min or max is a root
+            if (yMin == 0.0) {
+                ret = min;
+            } else {
+                ret = max;
+            }
         }
 
-        // solve using only the first endpoint as initial guess
-        return solve(min, yMin, max, yMax, min, yMin);
-
+        return ret;
     }
         
     /**

Modified: commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/transform/FastCosineTransformer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/transform/FastCosineTransformer.java?rev=670569&r1=670568&r2=670569&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/transform/FastCosineTransformer.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/java/org/apache/commons/math/transform/FastCosineTransformer.java
Mon Jun 23 06:46:46 2008
@@ -34,7 +34,7 @@
  * power of 2 plus one. Users should especially pay attention to the
  * function transformation on how this affects the sampling.</p>
  *
- * @version $Revision$ $Date$
+ * @version $Revision:670469 $ $Date:2008-06-23 10:01:38 +0200 (lun., 23 juin 2008) $
  * @since 1.2
  */
 public class FastCosineTransformer implements Serializable {
@@ -53,7 +53,7 @@
      * Transform the given real data set.
      * <p>
      * The formula is $ F_n = (1/2) [f_0 + (-1)^n f_N] +
-     *                        \Sigma_{k=0}^{N-1} f_k \cos(\pi nk/N) $
+     *                        \Sigma_{k=1}^{N-1} f_k \cos(\pi nk/N) $
      * </p>
      * 
      * @param f the real data array to be transformed
@@ -71,7 +71,7 @@
      * Transform the given real function, sampled on the given interval.
      * <p>
      * The formula is $ F_n = (1/2) [f_0 + (-1)^n f_N] +
-     *                        \Sigma_{k=0}^{N-1} f_k \cos(\pi nk/N) $
+     *                        \Sigma_{k=1}^{N-1} f_k \cos(\pi nk/N) $
      * </p>
      * 
      * @param f the function to be sampled and transformed
@@ -94,7 +94,7 @@
      * Transform the given real data set.
      * <p>
      * The formula is $ F_n = \sqrt{1/2N} [f_0 + (-1)^n f_N] +
-     *                        \sqrt{2/N} \Sigma_{k=0}^{N-1} f_k \cos(\pi nk/N) $
+     *                        \sqrt{2/N} \Sigma_{k=1}^{N-1} f_k \cos(\pi nk/N) $
      * </p>
      * 
      * @param f the real data array to be transformed
@@ -113,7 +113,7 @@
      * Transform the given real function, sampled on the given interval.
      * <p>
      * The formula is $ F_n = \sqrt{1/2N} [f_0 + (-1)^n f_N] +
-     *                        \sqrt{2/N} \Sigma_{k=0}^{N-1} f_k \cos(\pi nk/N) $
+     *                        \sqrt{2/N} \Sigma_{k=1}^{N-1} f_k \cos(\pi nk/N) $
      *
      * </p>
      * 
@@ -138,7 +138,7 @@
      * Inversely transform the given real data set.
      * <p>
      * The formula is $ f_k = (1/N) [F_0 + (-1)^k F_N] +
-     *                        (2/N) \Sigma_{n=0}^{N-1} F_n \cos(\pi nk/N) $
+     *                        (2/N) \Sigma_{n=1}^{N-1} F_n \cos(\pi nk/N) $
      * </p>
      * 
      * @param f the real data array to be inversely transformed
@@ -157,7 +157,7 @@
      * Inversely transform the given real function, sampled on the given interval.
      * <p>
      * The formula is $ f_k = (1/N) [F_0 + (-1)^k F_N] +
-     *                        (2/N) \Sigma_{n=0}^{N-1} F_n \cos(\pi nk/N) $
+     *                        (2/N) \Sigma_{n=1}^{N-1} F_n \cos(\pi nk/N) $
      * </p>
      * 
      * @param f the function to be sampled and inversely transformed
@@ -181,7 +181,7 @@
      * Inversely transform the given real data set.
      * <p>
      * The formula is $ f_k = \sqrt{1/2N} [F_0 + (-1)^k F_N] +
-     *                        \sqrt{2/N} \Sigma_{n=0}^{N-1} F_n \cos(\pi nk/N) $
+     *                        \sqrt{2/N} \Sigma_{n=1}^{N-1} F_n \cos(\pi nk/N) $
      * </p>
      * 
      * @param f the real data array to be inversely transformed
@@ -199,7 +199,7 @@
      * Inversely transform the given real function, sampled on the given interval.
      * <p>
      * The formula is $ f_k = \sqrt{1/2N} [F_0 + (-1)^k F_N] +
-     *                        \sqrt{2/N} \Sigma_{n=0}^{N-1} F_n \cos(\pi nk/N) $
+     *                        \sqrt{2/N} \Sigma_{n=1}^{N-1} F_n \cos(\pi nk/N) $
      * </p>
      * 
      * @param f the function to be sampled and inversely transformed

Modified: commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml?rev=670569&r1=670568&r2=670569&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/branches/MATH_2_0/src/site/xdoc/changes.xml Mon Jun 23 06:46:46 2008
@@ -105,6 +105,9 @@
       </action>
     </release>
     <release version="1.3-SNAPSHOT" date="TBD" description="TBD">
+      <action dev="luc" type="fix" issue="MATH-205" due-to="Roman Werpachowski">
+        Fixed formula in fast cosine transformer javadoc comments.
+      </action>
       <action dev="brentworden" type="fix" issue="MATH-193" due-to="Michael Heuer and
Sebb">
         Javadoc and style fixes.
       </action>
@@ -123,6 +126,9 @@
       <action dev="brentworden" type="fix" issue="MATH-201" due-to="Peter Wyngaard">
         Fixed truncation error in t-test classes for large t values.
       </action>
+      <action dev="brentworden" type="fix" issue="MATH-204" due-to="Mick">
+        Added root checks for the endpoints.
+      </action>
     </release>
     <release version="1.2" date="2008-02-24"
     description="This release combines bug fixes and new features. Most notable

Modified: commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/analysis/BrentSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/analysis/BrentSolverTest.java?rev=670569&r1=670568&r2=670569&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/analysis/BrentSolverTest.java
(original)
+++ commons/proper/math/branches/MATH_2_0/src/test/org/apache/commons/math/analysis/BrentSolverTest.java
Mon Jun 23 06:46:46 2008
@@ -31,7 +31,7 @@
  * default absolute accuracy of 10E-8 for sinus and the quintic function around
  * zero, and 5..10 iterations for the other zeros.
  * 
- * @version $Revision$ $Date$ 
+ * @version $Revision:670469 $ $Date:2008-06-23 10:01:38 +0200 (lun., 23 juin 2008) $ 
  */
 public final class BrentSolverTest extends TestCase {
 
@@ -268,6 +268,18 @@
         assertEquals(result, 1.0, 1E-6);
     }
     
+    public void testRootEndpoints() throws Exception {
+        UnivariateRealFunction f = new SinFunction();
+        UnivariateRealSolver solver = new BrentSolver(f);
+        
+        // endpoint is root
+        double result = solver.solve(Math.PI, 4);
+        assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
+
+        result = solver.solve(3, Math.PI);
+        assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
+    }
+    
     public void testBadEndpoints() throws Exception {
         UnivariateRealFunction f = new SinFunction();
         UnivariateRealSolver solver = new BrentSolver(f);



Mime
View raw message