package ppmrmn;
/**
* An n x n square real matrix class with
* n = 4 for a spin I = 3/2,
* n = 6 for a spin I = 5/2,
* n = 8 for a spin I = 7/2,
* n = 10 for a spin I = 9/2.
*/
public class RealMat extends ComplexMat {
//--------------//
// Constructors //
//--------------//
/**
* Constructor of an n x n square real matrix.
* @param preal a double value square matrix
*/
public RealMat(double[][] preal) {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
re[i][j] = preal[i][j];
}
/**
* Default constructor of an n x n square real matrix with zeroed elements.
*/
public RealMat() {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
re[i][j] = 0;
}
//-------------------//
// Matrix operations //
//-------------------//
/**
* Provide the transpose of an n x n square real matrix.
* @param a the square real matrix
* @return the transposed square real matrix
*/
public RealMat transpose(RealMat a) {
RealMat c = new RealMat();
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
c.re[i][j] = a.re[j][i];
}
return c;
}
/**
* Multiply two n x n square matrices with different types.
* @param a the left-hand side square real matrix
* @param b the right-hand side square complex matrix
* @return the product matrix (a square complex matrix)
*/
public ComplexMat matMultiply(RealMat a, ComplexMat b) {
ComplexMat c = new ComplexMat();
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
for (int k = 0; k < n; k++) {
c.re[i][j] += a.re[i][k]*b.re[k][j];
c.im[i][j] += a.re[i][k]*b.im[k][j];
}
return c;
}
/**
* Multiply two n x n square matrices of different types.
* @param a the left-hand side square complex matrix
* @param b the right-hand side square real matrix
* @return the product matrix (a square complex matrix)
*/
public ComplexMat matMultiply(ComplexMat a, RealMat b) {
ComplexMat c = new ComplexMat();
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
for (int k = 0; k < n; k++) {
c.re[i][j] += a.re[i][k]*b.re[k][j];
c.im[i][j] += a.im[i][k]*b.re[k][j];
}
return c;
}
/**
* Multiply two n x n square real matrices.
* @param a the left-hand side square real matrix
* @param b the right-hand side square real matrix
* @return the product matrix (a square real matrix)
*/
public RealMat matMultiply(RealMat a, RealMat b) {
RealMat c = new RealMat();
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
for (int k = 0; k < n; k++)
c.re[i][j] += a.re[i][k]*b.re[k][j];
return c;
}
/**
* Add two n x n square real matrices.
* @param a the first square real matrix
* @param b the second square real matrix
* @return the sum matrix (a square real matrix)
*/
public RealMat matAddition(RealMat a, RealMat b) {
RealMat c = new RealMat();
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
c.re[i][j] = a.re[i][j] + b.re[i][j];
}
return c;
}
/**
* @return a transformation matrix with nonzero elements in the two diagonals
*/
public RealMat matTwoDiagonal() {
final double R2 = 0.5*Math.sqrt(2);
RealMat c = new RealMat();
for (int k = 0; k < n; k++) c.re[k][k] = R2;
for (int k = 0; k < n/2; k++) c.re[k][n - k - 1] = R2;
for (int k = n/2; k < n; k++) c.re[k][n - k - 1] = -R2;
return c;
}
}//end of class RealMat