I am a newbie to Java, Currently, I am practicing some codes of Java. So I am trying to build a Matrix class myself. However, I refers to the code from jama (http://math.nist.gov/javanumerics/jama/doc/Jama/Matrix.html). But I feel it quite strange. Here is the structure of Matrix class, Jama defined in the later part.
Can somebody help me explain why transpose() return X (in my thinking, the C array is stransposed elements of X,elements of X is same order. But why jama return X, and what is the role of C-array in this program?). Thank you so much.
public class Matrix
{
private double[][] A;// 2-D array to hold matrix element
private m,n ; // number of column and row.
// Some constructors but I would like to omit
//public methods:
// I don't understand this:
public Matrix transpose () {
Matrix X = new Matrix(n,m);
double[][] C = X.getArray();
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
C[j][i] = A[i][j];
}
}
return X; // While it returns X? seem that X does not transpose but C.
// it seems there is no connection between X and C. what is the role of C here?
}
public double[][] getArray () {
return A;
}
}