Please help me explain the Java mechanism for transpose a matrix (code is attached) -
i newbie java, currently, practicing codes of java. trying build matrix class myself. however, refers code jama (http://math.nist.gov/javanumerics/jama/doc/jama/matrix.html). feel quite strange. here structure of matrix class, jama defined in later part.
can me explain why transpose() return x (in thinking, c array stransposed elements of x,elements of x same order. why jama return x, , role of c-array in program?). thank much.
public class matrix { private double[][] a;// 2-d array hold matrix element private m,n ; // number of column , row. // constructors omit //public methods: // don't understand this: public matrix transpose () { matrix x = new matrix(n,m); double[][] c = x.getarray(); (int = 0; < m; i++) { (int j = 0; j < n; j++) { c[j][i] = a[i][j]; } } return x; // while returns x? seem x not transpose c. // seems there no connection between x , c. role of c here? } public double[][] getarray () { return a; } }
there connection between x , c. when call getarray() return a itself, not copy of a.
so in context of transpose() method, c same x.a.
you can read behaviour of reference variables in java
Comments
Post a Comment