commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r506713 [2/4] - in /jakarta/commons/proper/math/trunk: ./ src/java/org/apache/commons/math/analysis/ src/java/org/apache/commons/math/distribution/ src/java/org/apache/commons/math/fraction/ src/test/org/apache/commons/math/analysis/ src/te...
Date Mon, 12 Feb 2007 22:35:10 GMT
Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/FractionFormat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/ProperFractionFormat.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/ProperFractionFormat.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/ProperFractionFormat.java (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/ProperFractionFormat.java Mon Feb 12 14:35:08 2007
@@ -1,230 +1,230 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.fraction;
-
-import java.text.FieldPosition;
-import java.text.NumberFormat;
-import java.text.ParsePosition;
-
-import org.apache.commons.math.util.MathUtils;
-
-/**
- * Formats a Fraction number in proper format.  The number format for each of
- * the whole number, numerator and, denominator can be configured.
- * <p>
- * Minus signs are only allowed in the whole number part - i.e.,
- * "-3 1/2" is legitimate and denotes -7/2, but "-3 -1/2" is invalid and
- * will result in a <code>ParseException</code>.
- * 
- * @since 1.1
- * @version $Revision$ $Date$
- */
-public class ProperFractionFormat extends FractionFormat {
-    
-    /** Serializable version identifier */
-    private static final long serialVersionUID = -6337346779577272307L;
-    
-    /** The format used for the whole number. */
-    private NumberFormat wholeFormat;
-
-    /**
-     * Create a proper formatting instance with the default number format for
-     * the whole, numerator, and denominator.  
-     */
-    public ProperFractionFormat() {
-        this(getDefaultNumberFormat());
-    }
-    
-    /**
-     * Create a proper formatting instance with a custom number format for the
-     * whole, numerator, and denominator.
-     * @param format the custom format for the whole, numerator, and
-     *        denominator.
-     */
-    public ProperFractionFormat(NumberFormat format) {
-        this(format, (NumberFormat)format.clone(), (NumberFormat)format.clone());
-    }
-    
-    /**
-     * Create a proper formatting instance with a custom number format for each
-     * of the whole, numerator, and denominator.
-     * @param wholeFormat the custom format for the whole.
-     * @param numeratorFormat the custom format for the numerator.
-     * @param denominatorFormat the custom format for the denominator.
-     */
-    public ProperFractionFormat(NumberFormat wholeFormat,
-            NumberFormat numeratorFormat,
-            NumberFormat denominatorFormat)
-    {
-        super(numeratorFormat, denominatorFormat);
-        setWholeFormat(wholeFormat);
-    }
-    
-    /**
-     * Formats a {@link Fraction} object to produce a string.  The fraction
-     * is output in proper format.
-     *
-     * @param fraction the object to format.
-     * @param toAppendTo where the text is to be appended
-     * @param pos On input: an alignment field, if desired. On output: the
-     *            offsets of the alignment field
-     * @return the value passed in as toAppendTo.
-     */
-    public StringBuffer format(Fraction fraction, StringBuffer toAppendTo,
-            FieldPosition pos) {
-        
-        pos.setBeginIndex(0);
-        pos.setEndIndex(0);
-
-        int num = fraction.getNumerator();
-        int den = fraction.getDenominator();
-        int whole = num / den;
-        num = num % den;
-        
-        if (whole != 0) {
-            getWholeFormat().format(whole, toAppendTo, pos);
-            toAppendTo.append(' ');
-            num = Math.abs(num);
-        }
-        getNumeratorFormat().format(num, toAppendTo, pos);
-        toAppendTo.append(" / ");
-        getDenominatorFormat().format(den, toAppendTo,
-            pos);
-        
-        return toAppendTo;
-    }
-
-    /**
-     * Access the whole format.
-     * @return the whole format.
-     */
-    public NumberFormat getWholeFormat() {
-        return wholeFormat;
-    }
-    
-    /**
-     * Parses a string to produce a {@link Fraction} object.  This method
-     * expects the string to be formatted as a proper fraction.
-     * <p>
-     * Minus signs are only allowed in the whole number part - i.e.,
-     * "-3 1/2" is legitimate and denotes -7/2, but "-3 -1/2" is invalid and
-     * will result in a <code>ParseException</code>.
-     * 
-     * @param source the string to parse
-     * @param pos input/ouput parsing parameter.
-     * @return the parsed {@link Fraction} object.
-     */
-    public Fraction parse(String source, ParsePosition pos) {
-        // try to parse improper fraction
-        Fraction ret = super.parse(source, pos);
-        if (ret != null) {
-            return ret;
-        }
-        
-        int initialIndex = pos.getIndex();
-
-        // parse whitespace
-        parseAndIgnoreWhitespace(source, pos);
-
-        // parse whole
-        Number whole = getWholeFormat().parse(source, pos);
-        if (whole == null) {
-            // invalid integer number
-            // set index back to initial, error index should already be set
-            // character examined.
-            pos.setIndex(initialIndex);
-            return null;
-        }
-
-        // parse whitespace
-        parseAndIgnoreWhitespace(source, pos);
-        
-        // parse numerator
-        Number num = getNumeratorFormat().parse(source, pos);
-        if (num == null) {
-            // invalid integer number
-            // set index back to initial, error index should already be set
-            // character examined.
-            pos.setIndex(initialIndex);
-            return null;
-        }
-        
-        if (num.intValue() < 0) {
-            // minus signs should be leading, invalid expression
-            pos.setIndex(initialIndex);
-            return null;
-        }
-
-        // parse '/'
-        int startIndex = pos.getIndex();
-        char c = parseNextCharacter(source, pos);
-        switch (c) {
-        case 0 :
-            // no '/'
-            // return num as a fraction
-            return new Fraction(num.intValue(), 1);
-        case '/' :
-            // found '/', continue parsing denominator
-            break;
-        default :
-            // invalid '/'
-            // set index back to initial, error index should be the last
-            // character examined.
-            pos.setIndex(initialIndex);
-            pos.setErrorIndex(startIndex);
-            return null;
-        }
-
-        // parse whitespace
-        parseAndIgnoreWhitespace(source, pos);
-
-        // parse denominator
-        Number den = getDenominatorFormat().parse(source, pos);
-        if (den == null) {
-            // invalid integer number
-            // set index back to initial, error index should already be set
-            // character examined.
-            pos.setIndex(initialIndex);
-            return null;
-        }
-        
-        if (den.intValue() < 0) {
-            // minus signs must be leading, invalid
-            pos.setIndex(initialIndex);
-            return null;
-        }
-
-        int w = whole.intValue();
-        int n = num.intValue();
-        int d = den.intValue();
-        return new Fraction(((Math.abs(w) * d) + n) * MathUtils.sign(w), d);
-    }
-    
-    /**
-     * Modify the whole format.
-     * @param format The new whole format value.
-     * @throws IllegalArgumentException if <code>format</code> is
-     *         <code>null</code>.
-     */
-    public void setWholeFormat(NumberFormat format) {
-        if (format == null) {
-            throw new IllegalArgumentException(
-                "whole format can not be null.");
-        }
-        this.wholeFormat = format;
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.fraction;
+
+import java.text.FieldPosition;
+import java.text.NumberFormat;
+import java.text.ParsePosition;
+
+import org.apache.commons.math.util.MathUtils;
+
+/**
+ * Formats a Fraction number in proper format.  The number format for each of
+ * the whole number, numerator and, denominator can be configured.
+ * <p>
+ * Minus signs are only allowed in the whole number part - i.e.,
+ * "-3 1/2" is legitimate and denotes -7/2, but "-3 -1/2" is invalid and
+ * will result in a <code>ParseException</code>.
+ * 
+ * @since 1.1
+ * @version $Revision$ $Date$
+ */
+public class ProperFractionFormat extends FractionFormat {
+    
+    /** Serializable version identifier */
+    private static final long serialVersionUID = -6337346779577272307L;
+    
+    /** The format used for the whole number. */
+    private NumberFormat wholeFormat;
+
+    /**
+     * Create a proper formatting instance with the default number format for
+     * the whole, numerator, and denominator.  
+     */
+    public ProperFractionFormat() {
+        this(getDefaultNumberFormat());
+    }
+    
+    /**
+     * Create a proper formatting instance with a custom number format for the
+     * whole, numerator, and denominator.
+     * @param format the custom format for the whole, numerator, and
+     *        denominator.
+     */
+    public ProperFractionFormat(NumberFormat format) {
+        this(format, (NumberFormat)format.clone(), (NumberFormat)format.clone());
+    }
+    
+    /**
+     * Create a proper formatting instance with a custom number format for each
+     * of the whole, numerator, and denominator.
+     * @param wholeFormat the custom format for the whole.
+     * @param numeratorFormat the custom format for the numerator.
+     * @param denominatorFormat the custom format for the denominator.
+     */
+    public ProperFractionFormat(NumberFormat wholeFormat,
+            NumberFormat numeratorFormat,
+            NumberFormat denominatorFormat)
+    {
+        super(numeratorFormat, denominatorFormat);
+        setWholeFormat(wholeFormat);
+    }
+    
+    /**
+     * Formats a {@link Fraction} object to produce a string.  The fraction
+     * is output in proper format.
+     *
+     * @param fraction the object to format.
+     * @param toAppendTo where the text is to be appended
+     * @param pos On input: an alignment field, if desired. On output: the
+     *            offsets of the alignment field
+     * @return the value passed in as toAppendTo.
+     */
+    public StringBuffer format(Fraction fraction, StringBuffer toAppendTo,
+            FieldPosition pos) {
+        
+        pos.setBeginIndex(0);
+        pos.setEndIndex(0);
+
+        int num = fraction.getNumerator();
+        int den = fraction.getDenominator();
+        int whole = num / den;
+        num = num % den;
+        
+        if (whole != 0) {
+            getWholeFormat().format(whole, toAppendTo, pos);
+            toAppendTo.append(' ');
+            num = Math.abs(num);
+        }
+        getNumeratorFormat().format(num, toAppendTo, pos);
+        toAppendTo.append(" / ");
+        getDenominatorFormat().format(den, toAppendTo,
+            pos);
+        
+        return toAppendTo;
+    }
+
+    /**
+     * Access the whole format.
+     * @return the whole format.
+     */
+    public NumberFormat getWholeFormat() {
+        return wholeFormat;
+    }
+    
+    /**
+     * Parses a string to produce a {@link Fraction} object.  This method
+     * expects the string to be formatted as a proper fraction.
+     * <p>
+     * Minus signs are only allowed in the whole number part - i.e.,
+     * "-3 1/2" is legitimate and denotes -7/2, but "-3 -1/2" is invalid and
+     * will result in a <code>ParseException</code>.
+     * 
+     * @param source the string to parse
+     * @param pos input/ouput parsing parameter.
+     * @return the parsed {@link Fraction} object.
+     */
+    public Fraction parse(String source, ParsePosition pos) {
+        // try to parse improper fraction
+        Fraction ret = super.parse(source, pos);
+        if (ret != null) {
+            return ret;
+        }
+        
+        int initialIndex = pos.getIndex();
+
+        // parse whitespace
+        parseAndIgnoreWhitespace(source, pos);
+
+        // parse whole
+        Number whole = getWholeFormat().parse(source, pos);
+        if (whole == null) {
+            // invalid integer number
+            // set index back to initial, error index should already be set
+            // character examined.
+            pos.setIndex(initialIndex);
+            return null;
+        }
+
+        // parse whitespace
+        parseAndIgnoreWhitespace(source, pos);
+        
+        // parse numerator
+        Number num = getNumeratorFormat().parse(source, pos);
+        if (num == null) {
+            // invalid integer number
+            // set index back to initial, error index should already be set
+            // character examined.
+            pos.setIndex(initialIndex);
+            return null;
+        }
+        
+        if (num.intValue() < 0) {
+            // minus signs should be leading, invalid expression
+            pos.setIndex(initialIndex);
+            return null;
+        }
+
+        // parse '/'
+        int startIndex = pos.getIndex();
+        char c = parseNextCharacter(source, pos);
+        switch (c) {
+        case 0 :
+            // no '/'
+            // return num as a fraction
+            return new Fraction(num.intValue(), 1);
+        case '/' :
+            // found '/', continue parsing denominator
+            break;
+        default :
+            // invalid '/'
+            // set index back to initial, error index should be the last
+            // character examined.
+            pos.setIndex(initialIndex);
+            pos.setErrorIndex(startIndex);
+            return null;
+        }
+
+        // parse whitespace
+        parseAndIgnoreWhitespace(source, pos);
+
+        // parse denominator
+        Number den = getDenominatorFormat().parse(source, pos);
+        if (den == null) {
+            // invalid integer number
+            // set index back to initial, error index should already be set
+            // character examined.
+            pos.setIndex(initialIndex);
+            return null;
+        }
+        
+        if (den.intValue() < 0) {
+            // minus signs must be leading, invalid
+            pos.setIndex(initialIndex);
+            return null;
+        }
+
+        int w = whole.intValue();
+        int n = num.intValue();
+        int d = den.intValue();
+        return new Fraction(((Math.abs(w) * d) + n) * MathUtils.sign(w), d);
+    }
+    
+    /**
+     * Modify the whole format.
+     * @param format The new whole format value.
+     * @throws IllegalArgumentException if <code>format</code> is
+     *         <code>null</code>.
+     */
+    public void setWholeFormat(NumberFormat format) {
+        if (format == null) {
+            throw new IllegalArgumentException(
+                "whole format can not be null.");
+        }
+        this.wholeFormat = format;
+    }
+}

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/ProperFractionFormat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/package.html
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/package.html?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/package.html (original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/package.html Mon Feb 12 14:35:08 2007
@@ -1,22 +1,22 @@
-<html>
-<!--
-   Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
-   this work for additional information regarding copyright ownership.
-   The ASF licenses this file to You under the Apache License, Version 2.0
-   (the "License"); you may not use this file except in compliance with
-   the License.  You may obtain a copy of the License at
-  
-        http://www.apache.org/licenses/LICENSE-2.0
-  
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-  -->
-    <!-- $Revision$ $Date$ -->
-  <body>
-    Fraction number type and fraction number formatting.
-  </body>
-</html>
+<html>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+  
+        http://www.apache.org/licenses/LICENSE-2.0
+  
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+  -->
+    <!-- $Revision$ $Date$ -->
+  <body>
+    Fraction number type and fraction number formatting.
+  </body>
+</html>

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/DividedDifferenceInterpolatorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/DividedDifferenceInterpolatorTest.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/DividedDifferenceInterpolatorTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/DividedDifferenceInterpolatorTest.java Mon Feb 12 14:35:08 2007
@@ -1,138 +1,138 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.analysis;
-
-import org.apache.commons.math.MathException;
-import junit.framework.TestCase;
-
-/**
- * Testcase for Divided Difference interpolator.
- * <p>
- * The error of polynomial interpolation is
- *     f(z) - p(z) = f^(n)(zeta) * (z-x[0])(z-x[1])...(z-x[n-1]) / n!
- * where f^(n) is the n-th derivative of the approximated function and
- * zeta is some point in the interval determined by x[] and z.
- * <p>
- * Since zeta is unknown, f^(n)(zeta) cannot be calculated. But we can bound
- * it and use the absolute value upper bound for estimates. For reference,
- * see <b>Introduction to Numerical Analysis</b>, ISBN 038795452X, chapter 2.
- * 
- * @version $Revision$ $Date$ 
- */
-public final class DividedDifferenceInterpolatorTest extends TestCase {
-
-    /**
-     * Test of interpolator for the sine function.
-     * <p>
-     * |sin^(n)(zeta)| <= 1.0, zeta in [0, 2*PI]
-     */
-    public void testSinFunction() throws MathException {
-        UnivariateRealFunction f = new SinFunction();
-        UnivariateRealInterpolator interpolator = new DividedDifferenceInterpolator();
-        double x[], y[], z, expected, result, tolerance;
-
-        // 6 interpolating points on interval [0, 2*PI]
-        int n = 6;
-        double min = 0.0, max = 2 * Math.PI;
-        x = new double[n];
-        y = new double[n];
-        for (int i = 0; i < n; i++) {
-            x[i] = min + i * (max - min) / n;
-            y[i] = f.value(x[i]);
-        }
-        double derivativebound = 1.0;
-        UnivariateRealFunction p = interpolator.interpolate(x, y);
-
-        z = Math.PI / 4; expected = f.value(z); result = p.value(z);
-        tolerance = Math.abs(derivativebound * partialerror(x, z));
-        assertEquals(expected, result, tolerance);
-
-        z = Math.PI * 1.5; expected = f.value(z); result = p.value(z);
-        tolerance = Math.abs(derivativebound * partialerror(x, z));
-        assertEquals(expected, result, tolerance);
-    }
-
-    /**
-     * Test of interpolator for the exponential function.
-     * <p>
-     * |expm1^(n)(zeta)| <= e, zeta in [-1, 1]
-     */
-    public void testExpm1Function() throws MathException {
-        UnivariateRealFunction f = new Expm1Function();
-        UnivariateRealInterpolator interpolator = new DividedDifferenceInterpolator();
-        double x[], y[], z, expected, result, tolerance;
-
-        // 5 interpolating points on interval [-1, 1]
-        int n = 5;
-        double min = -1.0, max = 1.0;
-        x = new double[n];
-        y = new double[n];
-        for (int i = 0; i < n; i++) {
-            x[i] = min + i * (max - min) / n;
-            y[i] = f.value(x[i]);
-        }
-        double derivativebound = Math.E;
-        UnivariateRealFunction p = interpolator.interpolate(x, y);
-
-        z = 0.0; expected = f.value(z); result = p.value(z);
-        tolerance = Math.abs(derivativebound * partialerror(x, z));
-        assertEquals(expected, result, tolerance);
-
-        z = 0.5; expected = f.value(z); result = p.value(z);
-        tolerance = Math.abs(derivativebound * partialerror(x, z));
-        assertEquals(expected, result, tolerance);
-
-        z = -0.5; expected = f.value(z); result = p.value(z);
-        tolerance = Math.abs(derivativebound * partialerror(x, z));
-        assertEquals(expected, result, tolerance);
-    }
-
-    /**
-     * Test of parameters for the interpolator.
-     */
-    public void testParameters() throws Exception {
-        UnivariateRealInterpolator interpolator = new DividedDifferenceInterpolator();
-
-        try {
-            // bad abscissas array
-            double x[] = { 1.0, 2.0, 2.0, 4.0 };
-            double y[] = { 0.0, 4.0, 4.0, 2.5 };
-            UnivariateRealFunction p = interpolator.interpolate(x, y);
-            p.value(0.0);
-            fail("Expecting MathException - bad abscissas array");
-        } catch (MathException ex) {
-            // expected
-        }
-    }
-
-    /**
-     * Returns the partial error term (z-x[0])(z-x[1])...(z-x[n-1])/n!
-     */
-    protected double partialerror(double x[], double z) throws
-        IllegalArgumentException {
-
-        if (x.length < 1) {
-            throw new IllegalArgumentException
-                ("Interpolation array cannot be empty.");
-        }
-        double out = 1;
-        for (int i = 0; i < x.length; i++) {
-            out *= (z - x[i]) / (i + 1);
-        }
-        return out;
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.analysis;
+
+import org.apache.commons.math.MathException;
+import junit.framework.TestCase;
+
+/**
+ * Testcase for Divided Difference interpolator.
+ * <p>
+ * The error of polynomial interpolation is
+ *     f(z) - p(z) = f^(n)(zeta) * (z-x[0])(z-x[1])...(z-x[n-1]) / n!
+ * where f^(n) is the n-th derivative of the approximated function and
+ * zeta is some point in the interval determined by x[] and z.
+ * <p>
+ * Since zeta is unknown, f^(n)(zeta) cannot be calculated. But we can bound
+ * it and use the absolute value upper bound for estimates. For reference,
+ * see <b>Introduction to Numerical Analysis</b>, ISBN 038795452X, chapter 2.
+ * 
+ * @version $Revision$ $Date$ 
+ */
+public final class DividedDifferenceInterpolatorTest extends TestCase {
+
+    /**
+     * Test of interpolator for the sine function.
+     * <p>
+     * |sin^(n)(zeta)| <= 1.0, zeta in [0, 2*PI]
+     */
+    public void testSinFunction() throws MathException {
+        UnivariateRealFunction f = new SinFunction();
+        UnivariateRealInterpolator interpolator = new DividedDifferenceInterpolator();
+        double x[], y[], z, expected, result, tolerance;
+
+        // 6 interpolating points on interval [0, 2*PI]
+        int n = 6;
+        double min = 0.0, max = 2 * Math.PI;
+        x = new double[n];
+        y = new double[n];
+        for (int i = 0; i < n; i++) {
+            x[i] = min + i * (max - min) / n;
+            y[i] = f.value(x[i]);
+        }
+        double derivativebound = 1.0;
+        UnivariateRealFunction p = interpolator.interpolate(x, y);
+
+        z = Math.PI / 4; expected = f.value(z); result = p.value(z);
+        tolerance = Math.abs(derivativebound * partialerror(x, z));
+        assertEquals(expected, result, tolerance);
+
+        z = Math.PI * 1.5; expected = f.value(z); result = p.value(z);
+        tolerance = Math.abs(derivativebound * partialerror(x, z));
+        assertEquals(expected, result, tolerance);
+    }
+
+    /**
+     * Test of interpolator for the exponential function.
+     * <p>
+     * |expm1^(n)(zeta)| <= e, zeta in [-1, 1]
+     */
+    public void testExpm1Function() throws MathException {
+        UnivariateRealFunction f = new Expm1Function();
+        UnivariateRealInterpolator interpolator = new DividedDifferenceInterpolator();
+        double x[], y[], z, expected, result, tolerance;
+
+        // 5 interpolating points on interval [-1, 1]
+        int n = 5;
+        double min = -1.0, max = 1.0;
+        x = new double[n];
+        y = new double[n];
+        for (int i = 0; i < n; i++) {
+            x[i] = min + i * (max - min) / n;
+            y[i] = f.value(x[i]);
+        }
+        double derivativebound = Math.E;
+        UnivariateRealFunction p = interpolator.interpolate(x, y);
+
+        z = 0.0; expected = f.value(z); result = p.value(z);
+        tolerance = Math.abs(derivativebound * partialerror(x, z));
+        assertEquals(expected, result, tolerance);
+
+        z = 0.5; expected = f.value(z); result = p.value(z);
+        tolerance = Math.abs(derivativebound * partialerror(x, z));
+        assertEquals(expected, result, tolerance);
+
+        z = -0.5; expected = f.value(z); result = p.value(z);
+        tolerance = Math.abs(derivativebound * partialerror(x, z));
+        assertEquals(expected, result, tolerance);
+    }
+
+    /**
+     * Test of parameters for the interpolator.
+     */
+    public void testParameters() throws Exception {
+        UnivariateRealInterpolator interpolator = new DividedDifferenceInterpolator();
+
+        try {
+            // bad abscissas array
+            double x[] = { 1.0, 2.0, 2.0, 4.0 };
+            double y[] = { 0.0, 4.0, 4.0, 2.5 };
+            UnivariateRealFunction p = interpolator.interpolate(x, y);
+            p.value(0.0);
+            fail("Expecting MathException - bad abscissas array");
+        } catch (MathException ex) {
+            // expected
+        }
+    }
+
+    /**
+     * Returns the partial error term (z-x[0])(z-x[1])...(z-x[n-1])/n!
+     */
+    protected double partialerror(double x[], double z) throws
+        IllegalArgumentException {
+
+        if (x.length < 1) {
+            throw new IllegalArgumentException
+                ("Interpolation array cannot be empty.");
+        }
+        double out = 1;
+        for (int i = 0; i < x.length; i++) {
+            out *= (z - x[i]) / (i + 1);
+        }
+        return out;
+    }
+}

Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/DividedDifferenceInterpolatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/DividedDifferenceInterpolatorTest.java
            ('svn:executable' removed)

Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/Expm1Function.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/Expm1Function.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/Expm1Function.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/Expm1Function.java Mon Feb 12 14:35:08 2007
@@ -1,40 +1,40 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.analysis;
-
-import org.apache.commons.math.FunctionEvaluationException;
-
-/**
- * Auxillary class for testing purposes.
- *
- * @version $Revision$ $Date$
- */
-public class Expm1Function implements DifferentiableUnivariateRealFunction {
-
-    public double value(double x) throws FunctionEvaluationException {
-        // Math.expm1() is available in jdk 1.5 but not in jdk 1.4.2.
-        return Math.exp(x) - 1.0;
-    }
-
-    public UnivariateRealFunction derivative() {
-        return new UnivariateRealFunction() {
-            public double value(double x) throws FunctionEvaluationException {
-                return Math.exp(x);
-            }
-        };
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.analysis;
+
+import org.apache.commons.math.FunctionEvaluationException;
+
+/**
+ * Auxillary class for testing purposes.
+ *
+ * @version $Revision$ $Date$
+ */
+public class Expm1Function implements DifferentiableUnivariateRealFunction {
+
+    public double value(double x) throws FunctionEvaluationException {
+        // Math.expm1() is available in jdk 1.5 but not in jdk 1.4.2.
+        return Math.exp(x) - 1.0;
+    }
+
+    public UnivariateRealFunction derivative() {
+        return new UnivariateRealFunction() {
+            public double value(double x) throws FunctionEvaluationException {
+                return Math.exp(x);
+            }
+        };
+    }
+}

Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/Expm1Function.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/Expm1Function.java
            ('svn:executable' removed)

Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/LaguerreSolverTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/LaguerreSolverTest.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/LaguerreSolverTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/LaguerreSolverTest.java Mon Feb 12 14:35:08 2007
@@ -1,178 +1,178 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.analysis;
-
-import org.apache.commons.math.MathException;
-import org.apache.commons.math.TestUtils;
-import org.apache.commons.math.complex.Complex;
-import junit.framework.TestCase;
-
-/**
- * Testcase for Laguerre solver.
- * <p>
- * Laguerre's method is very efficient in solving polynomials. Test runs
- * show that for a default absolute accuracy of 1E-6, it generally takes
- * less than 5 iterations to find one root, provided solveAll() is not
- * invoked, and 15 to 20 iterations to find all roots for quintic function.
- * 
- * @version $Revision$ $Date$ 
- */
-public final class LaguerreSolverTest extends TestCase {
-
-    /**
-     * Test of solver for the linear function.
-     */
-    public void testLinearFunction() throws MathException {
-        double min, max, expected, result, tolerance;
-
-        // p(x) = 4x - 1
-        double coefficients[] = { -1.0, 4.0 };
-        PolynomialFunction f = new PolynomialFunction(coefficients);
-        UnivariateRealSolver solver = new LaguerreSolver(f);
-
-        min = 0.0; max = 1.0; expected = 0.25;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
-        assertEquals(expected, result, tolerance);
-    }
-
-    /**
-     * Test of solver for the quadratic function.
-     */
-    public void testQuadraticFunction() throws MathException {
-        double min, max, expected, result, tolerance;
-
-        // p(x) = 2x^2 + 5x - 3 = (x+3)(2x-1)
-        double coefficients[] = { -3.0, 5.0, 2.0 };
-        PolynomialFunction f = new PolynomialFunction(coefficients);
-        UnivariateRealSolver solver = new LaguerreSolver(f);
-
-        min = 0.0; max = 2.0; expected = 0.5;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = -4.0; max = -1.0; expected = -3.0;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
-        assertEquals(expected, result, tolerance);
-    }
-
-    /**
-     * Test of solver for the quintic function.
-     */
-    public void testQuinticFunction() throws MathException {
-        double min, max, expected, result, tolerance;
-
-        // p(x) = x^5 - x^4 - 12x^3 + x^2 - x - 12 = (x+1)(x+3)(x-4)(x^2-x+1)
-        double coefficients[] = { -12.0, -1.0, 1.0, -12.0, -1.0, 1.0 };
-        PolynomialFunction f = new PolynomialFunction(coefficients);
-        UnivariateRealSolver solver = new LaguerreSolver(f);
-
-        min = -2.0; max = 2.0; expected = -1.0;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = -5.0; max = -2.5; expected = -3.0;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = 3.0; max = 6.0; expected = 4.0;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
-        assertEquals(expected, result, tolerance);
-    }
-
-    /**
-     * Test of solver for the quintic function using solveAll().
-     */
-    public void testQuinticFunction2() throws MathException {
-        double initial = 0.0, tolerance;
-        Complex expected, result[];
-
-        // p(x) = x^5 + 4x^3 + x^2 + 4 = (x+1)(x^2-x+1)(x^2+4)
-        double coefficients[] = { 4.0, 0.0, 1.0, 4.0, 0.0, 1.0 };
-        PolynomialFunction f = new PolynomialFunction(coefficients);
-        LaguerreSolver solver = new LaguerreSolver(f);
-        result = solver.solveAll(coefficients, initial);
-
-        expected = new Complex(0.0, -2.0);
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected.abs() * solver.getRelativeAccuracy()));
-        TestUtils.assertContains(result, expected, tolerance);
-
-        expected = new Complex(0.0, 2.0);
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected.abs() * solver.getRelativeAccuracy()));
-        TestUtils.assertContains(result, expected, tolerance);
-
-        expected = new Complex(0.5, 0.5 * Math.sqrt(3.0));
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected.abs() * solver.getRelativeAccuracy()));
-        TestUtils.assertContains(result, expected, tolerance);
-
-        expected = new Complex(-1.0, 0.0);
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected.abs() * solver.getRelativeAccuracy()));
-        TestUtils.assertContains(result, expected, tolerance);
-        
-        expected = new Complex(0.5, -0.5 * Math.sqrt(3.0));
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected.abs() * solver.getRelativeAccuracy()));
-        TestUtils.assertContains(result, expected, tolerance);
-    }
-
-    /**
-     * Test of parameters for the solver.
-     */
-    public void testParameters() throws Exception {
-        double coefficients[] = { -3.0, 5.0, 2.0 };
-        PolynomialFunction f = new PolynomialFunction(coefficients);
-        UnivariateRealSolver solver = new LaguerreSolver(f);
-
-        try {
-            // bad interval
-            solver.solve(1, -1);
-            fail("Expecting IllegalArgumentException - bad interval");
-        } catch (IllegalArgumentException ex) {
-            // expected
-        }
-        try {
-            // no bracketing
-            solver.solve(2, 3);
-            fail("Expecting IllegalArgumentException - no bracketing");
-        } catch (IllegalArgumentException ex) {
-            // expected
-        }
-        try {
-            // bad function
-            UnivariateRealFunction f2 = new SinFunction();
-            UnivariateRealSolver solver2 = new LaguerreSolver(f2);
-            fail("Expecting IllegalArgumentException - bad function");
-        } catch (IllegalArgumentException ex) {
-            // expected
-        }
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.analysis;
+
+import org.apache.commons.math.MathException;
+import org.apache.commons.math.TestUtils;
+import org.apache.commons.math.complex.Complex;
+import junit.framework.TestCase;
+
+/**
+ * Testcase for Laguerre solver.
+ * <p>
+ * Laguerre's method is very efficient in solving polynomials. Test runs
+ * show that for a default absolute accuracy of 1E-6, it generally takes
+ * less than 5 iterations to find one root, provided solveAll() is not
+ * invoked, and 15 to 20 iterations to find all roots for quintic function.
+ * 
+ * @version $Revision$ $Date$ 
+ */
+public final class LaguerreSolverTest extends TestCase {
+
+    /**
+     * Test of solver for the linear function.
+     */
+    public void testLinearFunction() throws MathException {
+        double min, max, expected, result, tolerance;
+
+        // p(x) = 4x - 1
+        double coefficients[] = { -1.0, 4.0 };
+        PolynomialFunction f = new PolynomialFunction(coefficients);
+        UnivariateRealSolver solver = new LaguerreSolver(f);
+
+        min = 0.0; max = 1.0; expected = 0.25;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(min, max);
+        assertEquals(expected, result, tolerance);
+    }
+
+    /**
+     * Test of solver for the quadratic function.
+     */
+    public void testQuadraticFunction() throws MathException {
+        double min, max, expected, result, tolerance;
+
+        // p(x) = 2x^2 + 5x - 3 = (x+3)(2x-1)
+        double coefficients[] = { -3.0, 5.0, 2.0 };
+        PolynomialFunction f = new PolynomialFunction(coefficients);
+        UnivariateRealSolver solver = new LaguerreSolver(f);
+
+        min = 0.0; max = 2.0; expected = 0.5;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(min, max);
+        assertEquals(expected, result, tolerance);
+
+        min = -4.0; max = -1.0; expected = -3.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(min, max);
+        assertEquals(expected, result, tolerance);
+    }
+
+    /**
+     * Test of solver for the quintic function.
+     */
+    public void testQuinticFunction() throws MathException {
+        double min, max, expected, result, tolerance;
+
+        // p(x) = x^5 - x^4 - 12x^3 + x^2 - x - 12 = (x+1)(x+3)(x-4)(x^2-x+1)
+        double coefficients[] = { -12.0, -1.0, 1.0, -12.0, -1.0, 1.0 };
+        PolynomialFunction f = new PolynomialFunction(coefficients);
+        UnivariateRealSolver solver = new LaguerreSolver(f);
+
+        min = -2.0; max = 2.0; expected = -1.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(min, max);
+        assertEquals(expected, result, tolerance);
+
+        min = -5.0; max = -2.5; expected = -3.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(min, max);
+        assertEquals(expected, result, tolerance);
+
+        min = 3.0; max = 6.0; expected = 4.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(min, max);
+        assertEquals(expected, result, tolerance);
+    }
+
+    /**
+     * Test of solver for the quintic function using solveAll().
+     */
+    public void testQuinticFunction2() throws MathException {
+        double initial = 0.0, tolerance;
+        Complex expected, result[];
+
+        // p(x) = x^5 + 4x^3 + x^2 + 4 = (x+1)(x^2-x+1)(x^2+4)
+        double coefficients[] = { 4.0, 0.0, 1.0, 4.0, 0.0, 1.0 };
+        PolynomialFunction f = new PolynomialFunction(coefficients);
+        LaguerreSolver solver = new LaguerreSolver(f);
+        result = solver.solveAll(coefficients, initial);
+
+        expected = new Complex(0.0, -2.0);
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected.abs() * solver.getRelativeAccuracy()));
+        TestUtils.assertContains(result, expected, tolerance);
+
+        expected = new Complex(0.0, 2.0);
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected.abs() * solver.getRelativeAccuracy()));
+        TestUtils.assertContains(result, expected, tolerance);
+
+        expected = new Complex(0.5, 0.5 * Math.sqrt(3.0));
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected.abs() * solver.getRelativeAccuracy()));
+        TestUtils.assertContains(result, expected, tolerance);
+
+        expected = new Complex(-1.0, 0.0);
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected.abs() * solver.getRelativeAccuracy()));
+        TestUtils.assertContains(result, expected, tolerance);
+        
+        expected = new Complex(0.5, -0.5 * Math.sqrt(3.0));
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected.abs() * solver.getRelativeAccuracy()));
+        TestUtils.assertContains(result, expected, tolerance);
+    }
+
+    /**
+     * Test of parameters for the solver.
+     */
+    public void testParameters() throws Exception {
+        double coefficients[] = { -3.0, 5.0, 2.0 };
+        PolynomialFunction f = new PolynomialFunction(coefficients);
+        UnivariateRealSolver solver = new LaguerreSolver(f);
+
+        try {
+            // bad interval
+            solver.solve(1, -1);
+            fail("Expecting IllegalArgumentException - bad interval");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            // no bracketing
+            solver.solve(2, 3);
+            fail("Expecting IllegalArgumentException - no bracketing");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            // bad function
+            UnivariateRealFunction f2 = new SinFunction();
+            UnivariateRealSolver solver2 = new LaguerreSolver(f2);
+            fail("Expecting IllegalArgumentException - bad function");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+    }
+}

Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/LaguerreSolverTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/LaguerreSolverTest.java
            ('svn:executable' removed)

Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/MullerSolverTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/MullerSolverTest.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/MullerSolverTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/MullerSolverTest.java Mon Feb 12 14:35:08 2007
@@ -1,215 +1,215 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.analysis;
-
-import org.apache.commons.math.MathException;
-import junit.framework.TestCase;
-
-/**
- * Testcase for Muller solver.
- * <p>
- * Muller's method converges almost quadratically near roots, but it can
- * be very slow in regions far away from zeros. Test runs show that for
- * reasonably good initial values, for a default absolute accuracy of 1E-6,
- * it generally takes 5 to 10 iterations for the solver to converge.
- * <p>
- * Tests for the exponential function illustrate the situations where
- * Muller solver performs poorly.
- * 
- * @version $Revision$ $Date$ 
- */
-public final class MullerSolverTest extends TestCase {
-
-    /**
-     * Test of solver for the sine function.
-     */
-    public void testSinFunction() throws MathException {
-        UnivariateRealFunction f = new SinFunction();
-        UnivariateRealSolver solver = new MullerSolver(f);
-        double min, max, expected, result, tolerance;
-
-        min = 3.0; max = 4.0; expected = Math.PI;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = -1.0; max = 1.5; expected = 0.0;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
-        assertEquals(expected, result, tolerance);
-    }
-
-    /**
-     * Test of solver for the sine function using solve2().
-     */
-    public void testSinFunction2() throws MathException {
-        UnivariateRealFunction f = new SinFunction();
-        MullerSolver solver = new MullerSolver(f);
-        double min, max, expected, result, tolerance;
-
-        min = 3.0; max = 4.0; expected = Math.PI;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = -1.0; max = 1.5; expected = 0.0;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(min, max);
-        assertEquals(expected, result, tolerance);
-    }
-
-    /**
-     * Test of solver for the quintic function.
-     */
-    public void testQuinticFunction() throws MathException {
-        UnivariateRealFunction f = new QuinticFunction();
-        UnivariateRealSolver solver = new MullerSolver(f);
-        double min, max, expected, result, tolerance;
-
-        min = -0.4; max = 0.2; expected = 0.0;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = 0.75; max = 1.5; expected = 1.0;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = -0.9; max = -0.2; expected = -0.5;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
-        assertEquals(expected, result, tolerance);
-    }
-
-    /**
-     * Test of solver for the quintic function using solve2().
-     */
-    public void testQuinticFunction2() throws MathException {
-        UnivariateRealFunction f = new QuinticFunction();
-        MullerSolver solver = new MullerSolver(f);
-        double min, max, expected, result, tolerance;
-
-        min = -0.4; max = 0.2; expected = 0.0;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = 0.75; max = 1.5; expected = 1.0;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = -0.9; max = -0.2; expected = -0.5;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(min, max);
-        assertEquals(expected, result, tolerance);
-    }
-
-    /**
-     * Test of solver for the exponential function.
-     * <p>
-     * It takes 10 to 15 iterations for the last two tests to converge.
-     * In fact, if not for the bisection alternative, the solver would
-     * exceed the default maximal iteration of 100.
-     */
-    public void testExpm1Function() throws MathException {
-        UnivariateRealFunction f = new Expm1Function();
-        UnivariateRealSolver solver = new MullerSolver(f);
-        double min, max, expected, result, tolerance;
-
-        min = -1.0; max = 2.0; expected = 0.0;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = -20.0; max = 10.0; expected = 0.0;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = -50.0; max = 100.0; expected = 0.0;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve(min, max);
-        assertEquals(expected, result, tolerance);
-    }
-
-    /**
-     * Test of solver for the exponential function using solve2().
-     * <p>
-     * It takes 25 to 50 iterations for the last two tests to converge.
-     */
-    public void testExpm1Function2() throws MathException {
-        UnivariateRealFunction f = new Expm1Function();
-        MullerSolver solver = new MullerSolver(f);
-        double min, max, expected, result, tolerance;
-
-        min = -1.0; max = 2.0; expected = 0.0;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = -20.0; max = 10.0; expected = 0.0;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(min, max);
-        assertEquals(expected, result, tolerance);
-
-        min = -50.0; max = 100.0; expected = 0.0;
-        tolerance = Math.max(solver.getAbsoluteAccuracy(),
-                    Math.abs(expected * solver.getRelativeAccuracy()));
-        result = solver.solve2(min, max);
-        assertEquals(expected, result, tolerance);
-    }
-
-    /**
-     * Test of parameters for the solver.
-     */
-    public void testParameters() throws Exception {
-        UnivariateRealFunction f = new SinFunction();
-        UnivariateRealSolver solver = new MullerSolver(f);
-
-        try {
-            // bad interval
-            solver.solve(1, -1);
-            fail("Expecting IllegalArgumentException - bad interval");
-        } catch (IllegalArgumentException ex) {
-            // expected
-        }
-        try {
-            // no bracketing
-            solver.solve(2, 3);
-            fail("Expecting IllegalArgumentException - no bracketing");
-        } catch (IllegalArgumentException ex) {
-            // expected
-        }
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.analysis;
+
+import org.apache.commons.math.MathException;
+import junit.framework.TestCase;
+
+/**
+ * Testcase for Muller solver.
+ * <p>
+ * Muller's method converges almost quadratically near roots, but it can
+ * be very slow in regions far away from zeros. Test runs show that for
+ * reasonably good initial values, for a default absolute accuracy of 1E-6,
+ * it generally takes 5 to 10 iterations for the solver to converge.
+ * <p>
+ * Tests for the exponential function illustrate the situations where
+ * Muller solver performs poorly.
+ * 
+ * @version $Revision$ $Date$ 
+ */
+public final class MullerSolverTest extends TestCase {
+
+    /**
+     * Test of solver for the sine function.
+     */
+    public void testSinFunction() throws MathException {
+        UnivariateRealFunction f = new SinFunction();
+        UnivariateRealSolver solver = new MullerSolver(f);
+        double min, max, expected, result, tolerance;
+
+        min = 3.0; max = 4.0; expected = Math.PI;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(min, max);
+        assertEquals(expected, result, tolerance);
+
+        min = -1.0; max = 1.5; expected = 0.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(min, max);
+        assertEquals(expected, result, tolerance);
+    }
+
+    /**
+     * Test of solver for the sine function using solve2().
+     */
+    public void testSinFunction2() throws MathException {
+        UnivariateRealFunction f = new SinFunction();
+        MullerSolver solver = new MullerSolver(f);
+        double min, max, expected, result, tolerance;
+
+        min = 3.0; max = 4.0; expected = Math.PI;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve2(min, max);
+        assertEquals(expected, result, tolerance);
+
+        min = -1.0; max = 1.5; expected = 0.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve2(min, max);
+        assertEquals(expected, result, tolerance);
+    }
+
+    /**
+     * Test of solver for the quintic function.
+     */
+    public void testQuinticFunction() throws MathException {
+        UnivariateRealFunction f = new QuinticFunction();
+        UnivariateRealSolver solver = new MullerSolver(f);
+        double min, max, expected, result, tolerance;
+
+        min = -0.4; max = 0.2; expected = 0.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(min, max);
+        assertEquals(expected, result, tolerance);
+
+        min = 0.75; max = 1.5; expected = 1.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(min, max);
+        assertEquals(expected, result, tolerance);
+
+        min = -0.9; max = -0.2; expected = -0.5;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(min, max);
+        assertEquals(expected, result, tolerance);
+    }
+
+    /**
+     * Test of solver for the quintic function using solve2().
+     */
+    public void testQuinticFunction2() throws MathException {
+        UnivariateRealFunction f = new QuinticFunction();
+        MullerSolver solver = new MullerSolver(f);
+        double min, max, expected, result, tolerance;
+
+        min = -0.4; max = 0.2; expected = 0.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve2(min, max);
+        assertEquals(expected, result, tolerance);
+
+        min = 0.75; max = 1.5; expected = 1.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve2(min, max);
+        assertEquals(expected, result, tolerance);
+
+        min = -0.9; max = -0.2; expected = -0.5;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve2(min, max);
+        assertEquals(expected, result, tolerance);
+    }
+
+    /**
+     * Test of solver for the exponential function.
+     * <p>
+     * It takes 10 to 15 iterations for the last two tests to converge.
+     * In fact, if not for the bisection alternative, the solver would
+     * exceed the default maximal iteration of 100.
+     */
+    public void testExpm1Function() throws MathException {
+        UnivariateRealFunction f = new Expm1Function();
+        UnivariateRealSolver solver = new MullerSolver(f);
+        double min, max, expected, result, tolerance;
+
+        min = -1.0; max = 2.0; expected = 0.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(min, max);
+        assertEquals(expected, result, tolerance);
+
+        min = -20.0; max = 10.0; expected = 0.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(min, max);
+        assertEquals(expected, result, tolerance);
+
+        min = -50.0; max = 100.0; expected = 0.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve(min, max);
+        assertEquals(expected, result, tolerance);
+    }
+
+    /**
+     * Test of solver for the exponential function using solve2().
+     * <p>
+     * It takes 25 to 50 iterations for the last two tests to converge.
+     */
+    public void testExpm1Function2() throws MathException {
+        UnivariateRealFunction f = new Expm1Function();
+        MullerSolver solver = new MullerSolver(f);
+        double min, max, expected, result, tolerance;
+
+        min = -1.0; max = 2.0; expected = 0.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve2(min, max);
+        assertEquals(expected, result, tolerance);
+
+        min = -20.0; max = 10.0; expected = 0.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve2(min, max);
+        assertEquals(expected, result, tolerance);
+
+        min = -50.0; max = 100.0; expected = 0.0;
+        tolerance = Math.max(solver.getAbsoluteAccuracy(),
+                    Math.abs(expected * solver.getRelativeAccuracy()));
+        result = solver.solve2(min, max);
+        assertEquals(expected, result, tolerance);
+    }
+
+    /**
+     * Test of parameters for the solver.
+     */
+    public void testParameters() throws Exception {
+        UnivariateRealFunction f = new SinFunction();
+        UnivariateRealSolver solver = new MullerSolver(f);
+
+        try {
+            // bad interval
+            solver.solve(1, -1);
+            fail("Expecting IllegalArgumentException - bad interval");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+        try {
+            // no bracketing
+            solver.solve(2, 3);
+            fail("Expecting IllegalArgumentException - no bracketing");
+        } catch (IllegalArgumentException ex) {
+            // expected
+        }
+    }
+}

Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/MullerSolverTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/MullerSolverTest.java
            ('svn:executable' removed)

Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/NevilleInterpolatorTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/NevilleInterpolatorTest.java?view=diff&rev=506713&r1=506712&r2=506713
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/NevilleInterpolatorTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/NevilleInterpolatorTest.java Mon Feb 12 14:35:08 2007
@@ -1,138 +1,138 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.analysis;
-
-import org.apache.commons.math.MathException;
-import junit.framework.TestCase;
-
-/**
- * Testcase for Neville interpolator.
- * <p>
- * The error of polynomial interpolation is
- *     f(z) - p(z) = f^(n)(zeta) * (z-x[0])(z-x[1])...(z-x[n-1]) / n!
- * where f^(n) is the n-th derivative of the approximated function and
- * zeta is some point in the interval determined by x[] and z.
- * <p>
- * Since zeta is unknown, f^(n)(zeta) cannot be calculated. But we can bound
- * it and use the absolute value upper bound for estimates. For reference,
- * see <b>Introduction to Numerical Analysis</b>, ISBN 038795452X, chapter 2.
- * 
- * @version $Revision$ $Date$ 
- */
-public final class NevilleInterpolatorTest extends TestCase {
-
-    /**
-     * Test of interpolator for the sine function.
-     * <p>
-     * |sin^(n)(zeta)| <= 1.0, zeta in [0, 2*PI]
-     */
-    public void testSinFunction() throws MathException {
-        UnivariateRealFunction f = new SinFunction();
-        UnivariateRealInterpolator interpolator = new NevilleInterpolator();
-        double x[], y[], z, expected, result, tolerance;
-
-        // 6 interpolating points on interval [0, 2*PI]
-        int n = 6;
-        double min = 0.0, max = 2 * Math.PI;
-        x = new double[n];
-        y = new double[n];
-        for (int i = 0; i < n; i++) {
-            x[i] = min + i * (max - min) / n;
-            y[i] = f.value(x[i]);
-        }
-        double derivativebound = 1.0;
-        UnivariateRealFunction p = interpolator.interpolate(x, y);
-
-        z = Math.PI / 4; expected = f.value(z); result = p.value(z);
-        tolerance = Math.abs(derivativebound * partialerror(x, z));
-        assertEquals(expected, result, tolerance);
-
-        z = Math.PI * 1.5; expected = f.value(z); result = p.value(z);
-        tolerance = Math.abs(derivativebound * partialerror(x, z));
-        assertEquals(expected, result, tolerance);
-    }
-
-    /**
-     * Test of interpolator for the exponential function.
-     * <p>
-     * |expm1^(n)(zeta)| <= e, zeta in [-1, 1]
-     */
-    public void testExpm1Function() throws MathException {
-        UnivariateRealFunction f = new Expm1Function();
-        UnivariateRealInterpolator interpolator = new NevilleInterpolator();
-        double x[], y[], z, expected, result, tolerance;
-
-        // 5 interpolating points on interval [-1, 1]
-        int n = 5;
-        double min = -1.0, max = 1.0;
-        x = new double[n];
-        y = new double[n];
-        for (int i = 0; i < n; i++) {
-            x[i] = min + i * (max - min) / n;
-            y[i] = f.value(x[i]);
-        }
-        double derivativebound = Math.E;
-        UnivariateRealFunction p = interpolator.interpolate(x, y);
-
-        z = 0.0; expected = f.value(z); result = p.value(z);
-        tolerance = Math.abs(derivativebound * partialerror(x, z));
-        assertEquals(expected, result, tolerance);
-
-        z = 0.5; expected = f.value(z); result = p.value(z);
-        tolerance = Math.abs(derivativebound * partialerror(x, z));
-        assertEquals(expected, result, tolerance);
-
-        z = -0.5; expected = f.value(z); result = p.value(z);
-        tolerance = Math.abs(derivativebound * partialerror(x, z));
-        assertEquals(expected, result, tolerance);
-    }
-
-    /**
-     * Test of parameters for the interpolator.
-     */
-    public void testParameters() throws Exception {
-        UnivariateRealInterpolator interpolator = new NevilleInterpolator();
-
-        try {
-            // bad abscissas array
-            double x[] = { 1.0, 2.0, 2.0, 4.0 };
-            double y[] = { 0.0, 4.0, 4.0, 2.5 };
-            UnivariateRealFunction p = interpolator.interpolate(x, y);
-            p.value(0.0);
-            fail("Expecting MathException - bad abscissas array");
-        } catch (MathException ex) {
-            // expected
-        }
-    }
-
-    /**
-     * Returns the partial error term (z-x[0])(z-x[1])...(z-x[n-1])/n!
-     */
-    protected double partialerror(double x[], double z) throws
-        IllegalArgumentException {
-
-        if (x.length < 1) {
-            throw new IllegalArgumentException
-                ("Interpolation array cannot be empty.");
-        }
-        double out = 1;
-        for (int i = 0; i < x.length; i++) {
-            out *= (z - x[i]) / (i + 1);
-        }
-        return out;
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.analysis;
+
+import org.apache.commons.math.MathException;
+import junit.framework.TestCase;
+
+/**
+ * Testcase for Neville interpolator.
+ * <p>
+ * The error of polynomial interpolation is
+ *     f(z) - p(z) = f^(n)(zeta) * (z-x[0])(z-x[1])...(z-x[n-1]) / n!
+ * where f^(n) is the n-th derivative of the approximated function and
+ * zeta is some point in the interval determined by x[] and z.
+ * <p>
+ * Since zeta is unknown, f^(n)(zeta) cannot be calculated. But we can bound
+ * it and use the absolute value upper bound for estimates. For reference,
+ * see <b>Introduction to Numerical Analysis</b>, ISBN 038795452X, chapter 2.
+ * 
+ * @version $Revision$ $Date$ 
+ */
+public final class NevilleInterpolatorTest extends TestCase {
+
+    /**
+     * Test of interpolator for the sine function.
+     * <p>
+     * |sin^(n)(zeta)| <= 1.0, zeta in [0, 2*PI]
+     */
+    public void testSinFunction() throws MathException {
+        UnivariateRealFunction f = new SinFunction();
+        UnivariateRealInterpolator interpolator = new NevilleInterpolator();
+        double x[], y[], z, expected, result, tolerance;
+
+        // 6 interpolating points on interval [0, 2*PI]
+        int n = 6;
+        double min = 0.0, max = 2 * Math.PI;
+        x = new double[n];
+        y = new double[n];
+        for (int i = 0; i < n; i++) {
+            x[i] = min + i * (max - min) / n;
+            y[i] = f.value(x[i]);
+        }
+        double derivativebound = 1.0;
+        UnivariateRealFunction p = interpolator.interpolate(x, y);
+
+        z = Math.PI / 4; expected = f.value(z); result = p.value(z);
+        tolerance = Math.abs(derivativebound * partialerror(x, z));
+        assertEquals(expected, result, tolerance);
+
+        z = Math.PI * 1.5; expected = f.value(z); result = p.value(z);
+        tolerance = Math.abs(derivativebound * partialerror(x, z));
+        assertEquals(expected, result, tolerance);
+    }
+
+    /**
+     * Test of interpolator for the exponential function.
+     * <p>
+     * |expm1^(n)(zeta)| <= e, zeta in [-1, 1]
+     */
+    public void testExpm1Function() throws MathException {
+        UnivariateRealFunction f = new Expm1Function();
+        UnivariateRealInterpolator interpolator = new NevilleInterpolator();
+        double x[], y[], z, expected, result, tolerance;
+
+        // 5 interpolating points on interval [-1, 1]
+        int n = 5;
+        double min = -1.0, max = 1.0;
+        x = new double[n];
+        y = new double[n];
+        for (int i = 0; i < n; i++) {
+            x[i] = min + i * (max - min) / n;
+            y[i] = f.value(x[i]);
+        }
+        double derivativebound = Math.E;
+        UnivariateRealFunction p = interpolator.interpolate(x, y);
+
+        z = 0.0; expected = f.value(z); result = p.value(z);
+        tolerance = Math.abs(derivativebound * partialerror(x, z));
+        assertEquals(expected, result, tolerance);
+
+        z = 0.5; expected = f.value(z); result = p.value(z);
+        tolerance = Math.abs(derivativebound * partialerror(x, z));
+        assertEquals(expected, result, tolerance);
+
+        z = -0.5; expected = f.value(z); result = p.value(z);
+        tolerance = Math.abs(derivativebound * partialerror(x, z));
+        assertEquals(expected, result, tolerance);
+    }
+
+    /**
+     * Test of parameters for the interpolator.
+     */
+    public void testParameters() throws Exception {
+        UnivariateRealInterpolator interpolator = new NevilleInterpolator();
+
+        try {
+            // bad abscissas array
+            double x[] = { 1.0, 2.0, 2.0, 4.0 };
+            double y[] = { 0.0, 4.0, 4.0, 2.5 };
+            UnivariateRealFunction p = interpolator.interpolate(x, y);
+            p.value(0.0);
+            fail("Expecting MathException - bad abscissas array");
+        } catch (MathException ex) {
+            // expected
+        }
+    }
+
+    /**
+     * Returns the partial error term (z-x[0])(z-x[1])...(z-x[n-1])/n!
+     */
+    protected double partialerror(double x[], double z) throws
+        IllegalArgumentException {
+
+        if (x.length < 1) {
+            throw new IllegalArgumentException
+                ("Interpolation array cannot be empty.");
+        }
+        double out = 1;
+        for (int i = 0; i < x.length; i++) {
+            out *= (z - x[i]) / (i + 1);
+        }
+        return out;
+    }
+}

Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/NevilleInterpolatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/NevilleInterpolatorTest.java
            ('svn:executable' removed)



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message