From b84b723efa91175a5779736242480942e3d6230e Mon Sep 17 00:00:00 2001 From: "Mark R. Diggory" Date: Sun, 23 Nov 2003 20:16:17 +0000 Subject: [PATCH] Patch to correct error in matrix multiply and the addition od toString method. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141045 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/math/linear/RealMatrixImpl.java | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/java/org/apache/commons/math/linear/RealMatrixImpl.java b/src/java/org/apache/commons/math/linear/RealMatrixImpl.java index cacabf6de..aebcfd0c7 100644 --- a/src/java/org/apache/commons/math/linear/RealMatrixImpl.java +++ b/src/java/org/apache/commons/math/linear/RealMatrixImpl.java @@ -78,7 +78,7 @@ import java.io.Serializable; * explicitly invoke LUDecompose() to recompute the decomposition * before using any of the methods above. * - * @version $Revision: 1.8 $ $Date: 2003/11/14 22:22:19 $ + * @version $Revision: 1.9 $ $Date: 2003/11/23 20:16:17 $ */ public class RealMatrixImpl implements RealMatrix, Serializable { @@ -249,7 +249,7 @@ public class RealMatrixImpl implements RealMatrix, Serializable { } return new RealMatrixImpl(outData); } - + /** * Returns the result postmultiplying this by m. * @param m matrix to postmultiply by @@ -263,15 +263,15 @@ public class RealMatrixImpl implements RealMatrix, Serializable { ("Matrices are not multiplication compatible."); } int nRows = this.getRowDimension(); - int nCols = this.getColumnDimension(); + int nCols = m.getColumnDimension(); + int nSum = this.getColumnDimension(); double[][] mData = m.getData(); - double[][] outData = - new double[nRows][nCols]; + double[][] outData = new double[nRows][nCols]; double sum = 0; for (int row = 0; row < nRows; row++) { for (int col = 0; col < nCols; col++) { sum = 0; - for (int i = 0; i < nCols; i++) { + for (int i = 0; i < nSum; i++) { sum += data[row][i] * mData[i][col]; } outData[row][col] = sum; @@ -720,6 +720,26 @@ public class RealMatrixImpl implements RealMatrix, Serializable { } } + /** + * + * @see java.lang.Object#toString() + */ + public String toString() { + StringBuffer res = new StringBuffer(); + res.append("RealMatrixImpl{"); + for (int i=0; i0) res.append(","); + res.append("{"); + for (int j=0; j0) res.append(","); + res.append(data[i][j]); + }//for + res.append("}"); + }//for + res.append("}"); + return res.toString(); + }//toString + //------------------------ Protected methods /**