You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by md...@apache.org on 2003/11/23 21:16:17 UTC
cvs commit: jakarta-commons/math/src/java/org/apache/commons/math/linear RealMatrixImpl.java
mdiggory 2003/11/23 12:16:17
Modified: math/src/java/org/apache/commons/math/linear
RealMatrixImpl.java
Log:
Patch to correct error in matrix multiply
and the addition od toString method.
Revision Changes Path
1.9 +26 -6 jakarta-commons/math/src/java/org/apache/commons/math/linear/RealMatrixImpl.java
Index: RealMatrixImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/linear/RealMatrixImpl.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- RealMatrixImpl.java 14 Nov 2003 22:22:19 -0000 1.8
+++ RealMatrixImpl.java 23 Nov 2003 20:16:17 -0000 1.9
@@ -249,7 +249,7 @@
}
return new RealMatrixImpl(outData);
}
-
+
/**
* Returns the result postmultiplying this by <code>m</code>.
* @param m matrix to postmultiply by
@@ -263,15 +263,15 @@
("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;
@@ -719,6 +719,26 @@
}
}
}
+
+ /**
+ *
+ * @see java.lang.Object#toString()
+ */
+ public String toString() {
+ StringBuffer res = new StringBuffer();
+ res.append("RealMatrixImpl{");
+ for (int i=0; i<data.length; i++) {
+ if (i>0) res.append(",");
+ res.append("{");
+ for (int j=0; j<data[0].length; j++) {
+ if (j>0) res.append(",");
+ res.append(data[i][j]);
+ }//for
+ res.append("}");
+ }//for
+ res.append("}");
+ return res.toString();
+ }//toString
//------------------------ Protected methods
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org