commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tobr...@apache.org
Subject cvs commit: jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis BrentSolver.java CubicSplineFunction.java SecantSolver.java UnivariateRealFunction.java UnivariateRealInterpolator.java UnivariateRealSolver.java UnivariateRealSolverFactory.java UnivariateFunction.java
Date Fri, 11 Jul 2003 15:59:15 GMT
tobrien     2003/07/11 08:59:15

  Modified:    math     project.properties
               math/src/java/org/apache/commons/math/analysis
                        BrentSolver.java CubicSplineFunction.java
                        SecantSolver.java UnivariateRealFunction.java
                        UnivariateRealInterpolator.java
                        UnivariateRealSolver.java
                        UnivariateRealSolverFactory.java
  Removed:     math/src/java/org/apache/commons/math/analysis
                        UnivariateFunction.java
  Log:
  Patch for bug 21516 from Brent Worden. Fixed checkstyle bugs and added maven.javadoc.links
to project.properties
  
  Revision  Changes    Path
  1.5       +8 -0      jakarta-commons-sandbox/math/project.properties
  
  Index: project.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/project.properties,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- project.properties	7 Jul 2003 13:57:13 -0000	1.4
  +++ project.properties	11 Jul 2003 15:59:14 -0000	1.5
  @@ -11,3 +11,11 @@
   maven.xdoc.version=${pom.currentVersion}
   maven.xdoc.developmentProcessUrl=http://jakarta.apache.org/commons/charter.html
   
  +maven.javadoc.links = http://java.sun.com/j2se/1.4.1/docs/api/,\
  +                      http://jakarta.apache.org/commons/collections/api/,\
  +                      http://jakarta.apache.org/commons/beanutils/api/,\
  +                      http://jakarta.apache.org/commons/logging/api/
  +maven.javadoc.links = http://java.sun.com/j2se/1.4.1/docs/api/,\
  +                      http://jakarta.apache.org/commons/collections/api/,\
  +                      http://jakarta.apache.org/commons/beanutils/api/,\
  +                      http://jakarta.apache.org/commons/logging/api/
  
  
  
  1.4       +5 -5      jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/BrentSolver.java
  
  Index: BrentSolver.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/BrentSolver.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BrentSolver.java	9 Jul 2003 20:02:43 -0000	1.3
  +++ BrentSolver.java	11 Jul 2003 15:59:14 -0000	1.4
  @@ -136,8 +136,8 @@
                   setResult(x1, i);
                   return result;
               }
  -            if (Math.abs(oldDelta) < tolerance
  -                || Math.abs(y0) <= Math.abs(y1)) {
  +            if ((Math.abs(oldDelta) < tolerance) ||
  +                    (Math.abs(y0) <= Math.abs(y1))) {
                   // Force bisection.
                   delta = 0.5 * dx;
                   oldDelta = delta;
  @@ -161,8 +161,8 @@
                   } else {
                       p = -p;
                   }
  -                if (2.0 * p >= 1.5 * dx * p1 - Math.abs(tolerance * p1)
  -                    || p >= Math.abs(0.5 * oldDelta * p1)) {
  +                if (2.0 * p >= 1.5 * dx * p1 - Math.abs(tolerance * p1) ||
  +                        p >= Math.abs(0.5 * oldDelta * p1)) {
                       // Inverse quadratic interpolation gives a value
                       // in the wrong direction, or progress is slow.
                       // Fall back to bisection.
  
  
  
  1.3       +66 -38    jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/CubicSplineFunction.java
  
  Index: CubicSplineFunction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/CubicSplineFunction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CubicSplineFunction.java	9 Jul 2003 20:02:43 -0000	1.2
  +++ CubicSplineFunction.java	11 Jul 2003 15:59:14 -0000	1.3
  @@ -65,70 +65,98 @@
    * Arguments outside of the domain cause an IllegalArgumentException.
    * 
    * @version $Revision$ $Date$
  - *
    */
   public class CubicSplineFunction implements UnivariateRealFunction {
  -    // Spline segment interval delimiters.
  -    // Size is N+1 for N segments.
  +    /** Spline segment interval delimiters. Size is N+1 for N segments. */
       private double xval[];
  -    
  -    // The spline segment's polynominal coefficients.
  -    // The first index runs over the intervals, size is N.
  -    // The second index adresses the coefficients in the segment, with
  -    // index 0 being the absolute coefficient and index 3 the coefficient
  -    // for the third power.
  -    // The coefficients are setup so that x runs from 0 to xval[i+1]-xval[i].
  +
  +    /**
  +     * The spline segment's polynominal coefficients.
  +     * The first index runs over the intervals, size is N.
  +     * The second index adresses the coefficients in the segment, with
  +     * index 0 being the absolute coefficient and index 3 the coefficient
  +     * for the third power.
  +     * The coefficients are setup so that x runs from 0 to xval[i+1]-xval[i].
  +     */
       private double c[][];
   
  -    public CubicSplineFunction(double xval[],double c[][]) {
  +    /**
  +     * Construct a function with the given segment delimiters and polynomial
  +     * coefficients.
  +     * @param xval Spline segment interval delimiters
  +     * @param c spline segment's polynominal coefficients
  +     */
  +    public CubicSplineFunction(double xval[], double c[][]) {
  +        super();
           // TODO: should copy the arguments here, for safety. This could be a major overhead.
  -        this.xval=xval;
  -        this.c=c;
  +        this.xval = xval;
  +        this.c = c;
       }
   
  -    /* (non-Javadoc)
  -     * @see org.apache.commons.math.UnivariateRealFunction#value(double)
  +    /**
  +     * Compute the value for the function.
  +     * @param x the point for which the function value should be computed
  +     * @return the value
  +     * @throws MathException if the function couldn't be computed due to
  +     *  missing additional data or other environmental problems.
  +     * @see UnivariateRealFunction#value(double)
        */
       public double value(double x) throws MathException {
  -        if(x<xval[0]||x>xval[xval.length-1]) {
  +        if (x < xval[0] || x > xval[xval.length - 1]) {
               throw new IllegalArgumentException("Argument outside domain");
           }
  -        int i=Arrays.binarySearch(xval,x);
  -        if(i<0) {
  -            i=-i-2;
  +        int i = Arrays.binarySearch(xval, x);
  +        if (i < 0) {
  +            i = -i - 2;
           }
  -        x=x-xval[i];
  -        return ((c[i][3]*x+c[i][2])*x+c[i][1])*x+c[i][0];
  +        x = x - xval[i];
  +        return ((c[i][3] * x + c[i][2]) * x + c[i][1]) * x + c[i][0];
       }
   
  -    /* (non-Javadoc)
  -     * @see org.apache.commons.math.UnivariateRealFunction#firstDerivative(double)
  +    /**
  +     * Compute the value for the first derivative of the function.
  +     * It is recommended to provide this method only if the first derivative is
  +     * analytical. Numerical derivatives may be acceptable in some cases.
  +     * An implementation should throw an UnsupportedOperationException if
  +     * this method is not implemented.
  +     * @param x the point for which the first derivative should be computed
  +     * @return the value
  +     * @throws MathException if the derivative couldn't be computed.
  +     * @see UnivariateRealFunction#firstDerivative(double)
        */
       public double firstDerivative(double x) throws MathException {
  -        if(x<xval[0]||x>xval[xval.length-1]) {
  +        if (x < xval[0] || x > xval[xval.length - 1]) {
               throw new IllegalArgumentException("Argument outside domain");
           }
  -        int i=Arrays.binarySearch(xval,x);
  -        if(i<0) {
  -            i=-i-2;
  +        int i = Arrays.binarySearch(xval, x);
  +        if (i < 0) {
  +            i = -i - 2;
           }
  -        x=x-xval[i];
  -        return (3*c[i][3]*x+2*c[i][2])*x+c[i][1];
  +        x = x - xval[i];
  +        return (3 * c[i][3] * x + 2 * c[i][2]) * x + c[i][1];
       }
   
  -    /* (non-Javadoc)
  -     * @see org.apache.commons.math.UnivariateRealFunction#secondDerivative(double)
  +    /**
  +     * Compute the value for the second derivative of the function.
  +     * It is recommended to provide this method only if the second derivative is
  +     * analytical. Numerical derivatives may be acceptable in some cases.
  +     * An implementation should throw an UnsupportedOperationException if
  +     * this method is not implemented.
  +     * @param x the point for which the first derivative should be computed
  +     * @return the value
  +     * @throws MathException if the second derivative couldn't be computed.
  +     * @see UnivariateRealFunction#secondDerivative(double)
        */
       public double secondDerivative(double x) throws MathException {
  -        if(x<xval[0]||x>xval[xval.length-1]) {
  +        if (x < xval[0] || x > xval[xval.length - 1]) {
               throw new IllegalArgumentException("Argument outside domain");
           }
  -        int i=Arrays.binarySearch(xval,x);
  -        if(i<0) {
  -            i=-i-2;
  +        int i = Arrays.binarySearch(xval, x);
  +        if (i < 0) {
  +            i = -i - 2;
           }
  -        x=x-xval[i];
  -        return 6*c[i][3]*x+2*c[i][2];
  +        x = x - xval[i];
  +        return 6 * c[i][3] * x + 2 * c[i][2];
       }
   
   }
  
  
  
  1.4       +3 -3      jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/SecantSolver.java
  
  Index: SecantSolver.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/SecantSolver.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SecantSolver.java	9 Jul 2003 20:02:43 -0000	1.3
  +++ SecantSolver.java	11 Jul 2003 15:59:14 -0000	1.4
  @@ -128,8 +128,8 @@
                   setResult(x1, i);
                   return result;
               }
  -            if (Math.abs(oldDelta)
  -                < Math.max(relativeAccuracy * Math.abs(x1), absoluteAccuracy)) {
  +            if (Math.abs(oldDelta) <
  +                Math.max(relativeAccuracy * Math.abs(x1), absoluteAccuracy)) {
                   setResult(x1, i);
                   return result;
               }
  
  
  
  1.3       +1 -5      jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/UnivariateRealFunction.java
  
  Index: UnivariateRealFunction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/UnivariateRealFunction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UnivariateRealFunction.java	9 Jul 2003 20:02:43 -0000	1.2
  +++ UnivariateRealFunction.java	11 Jul 2003 15:59:14 -0000	1.3
  @@ -65,7 +65,6 @@
    * @version $Revision$ $Date$
    */
   public interface UnivariateRealFunction {
  -
       /**
        * Compute the value for the function.
        * @param x the point for which the function value should be computed
  @@ -74,7 +73,6 @@
        *  missing additional data or other environmental problems.
        * @throws RuntimeException if the operation isn't supported, the argument
        *  was outside the supported domain or any other problem.
  -     * 
        */
       public double value(double x) throws MathException;
   
  @@ -89,7 +87,6 @@
        * @throws MathException if the derivative couldn't be computed.
        * @throws RuntimeException if the operation isn't supported, the argument
        *  was outside the supported domain or any other problem.
  -     * 
        */
       public double firstDerivative(double x) throws MathException;
   
  @@ -104,7 +101,6 @@
        * @throws MathException if the second derivative couldn't be computed.
        * @throws RuntimeException if the operation isn't supported, the argument
        *  was outside the supported domain or any other problem.
  -     * 
        */
       public double secondDerivative(double x) throws MathException;
   }
  
  
  
  1.3       +4 -3      jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/UnivariateRealInterpolator.java
  
  Index: UnivariateRealInterpolator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/UnivariateRealInterpolator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UnivariateRealInterpolator.java	9 Jul 2003 20:02:43 -0000	1.2
  +++ UnivariateRealInterpolator.java	11 Jul 2003 15:59:14 -0000	1.3
  @@ -56,7 +56,7 @@
   import org.apache.commons.math.MathException;
   
   /**
  - *  Interface for interpolating a data set.
  + * Interface for interpolating a data set.
    *  
    * @version $Revision$ $Date$
    */
  @@ -67,7 +67,8 @@
        * @param xval the arguments for the interpolation points
        * @param yval the values for the interpolation points
        * @return a function which interpolates the data set
  -     * @throws MathException if arguments violate assumptions made by the interpolationg
algorithm
  +     * @throws MathException if arguments violate assumptions made by the
  +     *         interpolationg algorithm
        */
       public UnivariateRealFunction interpolate(double xval[], double yval[])
           throws MathException;
  
  
  
  1.4       +3 -3      jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/UnivariateRealSolver.java
  
  Index: UnivariateRealSolver.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/UnivariateRealSolver.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- UnivariateRealSolver.java	9 Jul 2003 20:02:43 -0000	1.3
  +++ UnivariateRealSolver.java	11 Jul 2003 15:59:14 -0000	1.4
  @@ -184,7 +184,7 @@
        * A solver may require that the interval brackets a single zero root.
        * @param min the lower bound for the interval.
        * @param max the upper bound for the interval.
  -     * @return the value where the function is zero
  +     * @return a value where the function is zero
        * @throws MathException if the iteration count was exceeded or the
        *  solver detects convergence problems otherwise.
        */
  @@ -196,7 +196,7 @@
        * @param min the lower bound for the interval.
        * @param max the upper bound for the interval.
        * @param startValue the start value to use
  -     * @return the value where the function is zero
  +     * @return a value where the function is zero
        * @throws MathException if the iteration count was exceeded or the
        *  solver detects convergence problems otherwise.
        */
  
  
  
  1.3       +43 -6     jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/UnivariateRealSolverFactory.java
  
  Index: UnivariateRealSolverFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/UnivariateRealSolverFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UnivariateRealSolverFactory.java	9 Jul 2003 20:02:43 -0000	1.2
  +++ UnivariateRealSolverFactory.java	11 Jul 2003 15:59:14 -0000	1.3
  @@ -69,9 +69,26 @@
    * @version $Revision$ $Date$
    */
   public class UnivariateRealSolverFactory {
  -    protected UnivariateRealSolverFactory() {
  +    /**
  +     * Default constructor.
  +     */
  +    private UnivariateRealSolverFactory() {
       }
   
  +    /**
  +     * Create a new {@link UnivariateRealSolver} for the given function.  The
  +     * actual solver returned can be controlled by defining the
  +     * <code>org.apache.commons.math.analysis.UnivariateRealSolver</code>
  +     * property on the JVM command-line (<code>
  +     * -Dorg.apache.commons.math.analysis.UnivariateRealSolver=
  +     * <i>class name</i></code>).  The value of the property should be
any,
  +     * fully qualified class name for a type that implements the
  +     * {@link UnivariateRealSolver} interface.  By default, an instance of
  +     * {@link BrentSolver} is returned.
  +     * @param f the function.
  +     * @return the new solver.
  +     * @throws MathConfigurationException if a
  +     */
       public static UnivariateRealSolver newSolver(UnivariateRealFunction f)
           throws MathConfigurationException {
           String solverClassName =
  @@ -81,8 +98,7 @@
           try {
               Class clazz = Class.forName(solverClassName);
               Class paramClass[] = new Class[1];
  -            paramClass[0] =
  -                Class.forName("org.apache.commons.math.analysis.UnivariateRealFunction");
  +            paramClass[0] = UnivariateRealFunction.class;
               Object param[] = new Object[1];
               param[0] = f;
               return (UnivariateRealSolver)clazz.getConstructor(
  @@ -110,17 +126,38 @@
               throw new MathConfigurationException(e);
           } catch (NoSuchMethodException e) {
               throw new MathConfigurationException(
  -                "No constructor with UnivariateRealFunction in "
  -                    + solverClassName,
  +                "No constructor with UnivariateRealFunction in " +
  +                solverClassName,
                   e);
           }
       }
   
  +    /**
  +     * Convience method to solve for zeros of real univariate functions.  A
  +     * default solver is created and used for solving. 
  +     * @param f the function.
  +     * @param x0 the lower bound for the interval.
  +     * @param x1 the upper bound for the interval.
  +     * @return a value where the function is zero.
  +     * @throws MathException if the iteration count was exceeded or the
  +     *         solver detects convergence problems otherwise.
  +     */
       public static double solve(UnivariateRealFunction f, double x0, double x1)
           throws MathException {
           return newSolver(f).solve(x0, x1);
       }
   
  +    /**
  +     * Convience method to solve for zeros of real univariate functions.  A
  +     * default solver is created and used for solving. 
  +     * @param f the function.
  +     * @param x0 the lower bound for the interval.
  +     * @param x1 the upper bound for the interval.
  +     * @param absoluteAccuracy the accuracy to be used by the solver.
  +     * @return a value where the function is zero.
  +     * @throws MathException if the iteration count was exceeded or the
  +     *         solver detects convergence problems otherwise.
  +     */
       public static double solve(
           UnivariateRealFunction f,
           double x0,
  
  
  

---------------------------------------------------------------------
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