You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ce...@apache.org on 2011/09/06 08:20:31 UTC
svn commit: r1165506 -
/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/LUDecompositionImpl.java
Author: celestin
Date: Tue Sep 6 06:20:31 2011
New Revision: 1165506
URL: http://svn.apache.org/viewvc?rev=1165506&view=rev
Log:
Removed double[] solve(double[]) from LUDecompositionImpl.Solver
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/LUDecompositionImpl.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/LUDecompositionImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/LUDecompositionImpl.java?rev=1165506&r1=1165505&r2=1165506&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/LUDecompositionImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/linear/LUDecompositionImpl.java Tue Sep 6 06:20:31 2011
@@ -249,10 +249,10 @@ public class LUDecompositionImpl impleme
}
/** {@inheritDoc} */
- public double[] solve(double[] b) {
+ public RealVector solve(RealVector b) {
final int m = pivot.length;
- if (b.length != m) {
- throw new DimensionMismatchException(b.length, m);
+ if (b.getDimension() != m) {
+ throw new DimensionMismatchException(b.getDimension(), m);
}
if (singular) {
throw new SingularMatrixException();
@@ -262,7 +262,7 @@ public class LUDecompositionImpl impleme
// Apply permutations to b
for (int row = 0; row < m; row++) {
- bp[row] = b[pivot[row]];
+ bp[row] = b.getEntry(pivot[row]);
}
// Solve LY = b
@@ -282,61 +282,7 @@ public class LUDecompositionImpl impleme
}
}
- return bp;
- }
-
- /** {@inheritDoc} */
- public RealVector solve(RealVector b) {
- try {
- return solve((ArrayRealVector) b);
- } catch (ClassCastException cce) {
-
- final int m = pivot.length;
- if (b.getDimension() != m) {
- throw new DimensionMismatchException(b.getDimension(), m);
- }
- if (singular) {
- throw new SingularMatrixException();
- }
-
- final double[] bp = new double[m];
-
- // Apply permutations to b
- for (int row = 0; row < m; row++) {
- bp[row] = b.getEntry(pivot[row]);
- }
-
- // Solve LY = b
- for (int col = 0; col < m; col++) {
- final double bpCol = bp[col];
- for (int i = col + 1; i < m; i++) {
- bp[i] -= bpCol * lu[i][col];
- }
- }
-
- // Solve UX = Y
- for (int col = m - 1; col >= 0; col--) {
- bp[col] /= lu[col][col];
- final double bpCol = bp[col];
- for (int i = 0; i < col; i++) {
- bp[i] -= bpCol * lu[i][col];
- }
- }
-
- return new ArrayRealVector(bp, false);
- }
- }
-
- /** Solve the linear equation A × X = B.
- * <p>The A matrix is implicit here. It is </p>
- * @param b right-hand side of the equation A × X = B
- * @return a vector X such that A × X = B
- * @throws DimensionMismatchException if the matrices dimensions
- * do not match.
- * @throws SingularMatrixException if decomposed matrix is singular.
- */
- public ArrayRealVector solve(ArrayRealVector b) {
- return new ArrayRealVector(solve(b.getDataRef()), false);
+ return new ArrayRealVector(bp, false);
}
/** {@inheritDoc} */