You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2012/07/16 15:38:13 UTC

svn commit: r1362032 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/solvers/LaguerreSolver.java

Author: erans
Date: Mon Jul 16 13:38:12 2012
New Revision: 1362032

URL: http://svn.apache.org/viewvc?rev=1362032&view=rev
Log:
Code cleanup.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/solvers/LaguerreSolver.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/solvers/LaguerreSolver.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/solvers/LaguerreSolver.java?rev=1362032&r1=1362031&r2=1362032&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/solvers/LaguerreSolver.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/solvers/LaguerreSolver.java Mon Jul 16 13:38:12 2012
@@ -88,21 +88,21 @@ public class LaguerreSolver extends Abst
      */
     @Override
     public double doSolve() {
-        double min = getMin();
-        double max = getMax();
-        double initial = getStartValue();
+        final double min = getMin();
+        final double max = getMax();
+        final double initial = getStartValue();
         final double functionValueAccuracy = getFunctionValueAccuracy();
 
         verifySequence(min, initial, max);
 
         // Return the initial guess if it is good enough.
-        double yInitial = computeObjectiveValue(initial);
+        final double yInitial = computeObjectiveValue(initial);
         if (FastMath.abs(yInitial) <= functionValueAccuracy) {
             return initial;
         }
 
         // Return the first endpoint if it is good enough.
-        double yMin = computeObjectiveValue(min);
+        final double yMin = computeObjectiveValue(min);
         if (FastMath.abs(yMin) <= functionValueAccuracy) {
             return min;
         }
@@ -113,7 +113,7 @@ public class LaguerreSolver extends Abst
         }
 
         // Return the second endpoint if it is good enough.
-        double yMax = computeObjectiveValue(max);
+        final double yMax = computeObjectiveValue(max);
         if (FastMath.abs(yMax) <= functionValueAccuracy) {
             return max;
         }
@@ -151,8 +151,8 @@ public class LaguerreSolver extends Abst
                            double fLo, double fHi) {
         final Complex c[] = ComplexUtils.convertToComplex(getCoefficients());
 
-        Complex initial = new Complex(0.5 * (lo + hi), 0);
-        Complex z = complexSolver.solve(c, initial);
+        final Complex initial = new Complex(0.5 * (lo + hi), 0);
+        final Complex z = complexSolver.solve(c, initial);
         if (complexSolver.isRoot(lo, hi, z)) {
             return z.getReal();
         } else {
@@ -260,7 +260,7 @@ public class LaguerreSolver extends Abst
             if (coefficients == null) {
                 throw new NullArgumentException();
             }
-            int n = coefficients.length - 1;
+            final int n = coefficients.length - 1;
             if (n == 0) {
                 throw new NoDataException(LocalizedFormats.POLYNOMIAL);
             }
@@ -307,7 +307,7 @@ public class LaguerreSolver extends Abst
                 throw new NullArgumentException();
             }
 
-            int n = coefficients.length - 1;
+            final int n = coefficients.length - 1;
             if (n == 0) {
                 throw new NoDataException(LocalizedFormats.POLYNOMIAL);
             }
@@ -316,8 +316,8 @@ public class LaguerreSolver extends Abst
             final double relativeAccuracy = getRelativeAccuracy();
             final double functionValueAccuracy = getFunctionValueAccuracy();
 
-            final Complex N  = new Complex(n, 0);
-            final Complex N1 = new Complex(n - 1, 0);
+            final Complex nC  = new Complex(n, 0);
+            final Complex n1C = new Complex(n - 1, 0);
 
             Complex z = initial;
             Complex oldz = new Complex(Double.POSITIVE_INFINITY,
@@ -335,7 +335,7 @@ public class LaguerreSolver extends Abst
                 }
                 d2v = d2v.multiply(new Complex(2.0, 0.0));
 
-                // check for convergence
+                // Check for convergence.
                 final double tolerance = FastMath.max(relativeAccuracy * z.abs(),
                                                       absoluteAccuracy);
                 if ((z.subtract(oldz)).abs() <= tolerance) {
@@ -345,12 +345,12 @@ public class LaguerreSolver extends Abst
                     return z;
                 }
 
-                // now pv != 0, calculate the new approximation
+                // Now pv != 0, calculate the new approximation.
                 final Complex G = dv.divide(pv);
                 final Complex G2 = G.multiply(G);
                 final Complex H = G2.subtract(d2v.divide(pv));
-                final Complex delta = N1.multiply((N.multiply(H)).subtract(G2));
-                // choose a denominator larger in magnitude
+                final Complex delta = n1C.multiply((nC.multiply(H)).subtract(G2));
+                // Choose a denominator larger in magnitude.
                 final Complex deltaSqrt = delta.sqrt();
                 final Complex dplus = G.add(deltaSqrt);
                 final Complex dminus = G.subtract(deltaSqrt);
@@ -363,7 +363,7 @@ public class LaguerreSolver extends Abst
                                        Double.POSITIVE_INFINITY);
                 } else {
                     oldz = z;
-                    z = z.subtract(N.divide(denominator));
+                    z = z.subtract(nC.divide(denominator));
                 }
                 incrementEvaluationCount();
             }