Michael Thomas Flanagan's Java Scientific Library

PhasorMatrix Class:      Phasor Matrices

     

Last update: 14 November 2010
Main Page of Michael Thomas Flanagan Java Scientific Library

This class defines an object that represents a matrix of phasors [magnitude∠phase = magnitude.exp(j.phase)]. The instance variables are: It includes the methods needed for phasor matrix manipulations and for the solution of a set of phasor linear equations.
The Phasor constructor and the basic phasor methods may found in the Phasor class.

import directive: import flanagan.circuits.PhasorMatrix; Related classes

SUMMARY OF CONSTRUCTORS AND METHODS

Constructors   public PhasorMatrix(int nrow, int ncol)
  public PhasorMatrix(int nrow, int ncol, Phasor const)
  public PhasorMatrix(Phasor[][] twoD)
  public PhasorMatrix(PhasorMatrix matrix)
Create Special
Matrices
  public static PhasorMatrix identityMatrix(int nrow)
  public static PhasorMatrix scalarMatrix(int nrow, Phasor diagconst)
  public static PhasorMatrix diagonalMatrix(int nrow, Phasor[] diag)
Row Matrix   public static PhasorMatrix rowMatrix(Phasor[] oneDarray)
Column Matrix   public static PhasorMatrix columnMatrix(Phasor[] oneDarray)
Set values   public setTwoDarray(Phasor[][] twoD)
  public setElement(int i, int j, Phasor aa)
  public setElement(int i, int j, double magnitude, double phase)
  public setSubMatrix(int i, int j, Phasor[][] submat)
  public setSubMatrix(int i, int j, int k, int l, Phasor[][] submat)
  public setSubMatrix(int[] row, int[] col, Phasor[][] submat)
Get values   public int getNrow()
  public int getNcol()
  public Phasor[][] getArrayReference()
  public Phasor[][] getArrayCopy()
  public Phasor getElementReference(int i, int j)
  public Phasor getElementCopy(int i, int j)
  public PhasorMatrix getSubMatrix(int i, int j, int k, int l)
  public PhasorMatrix getSubMatrix(int[] row, int[] col)
  public int[] getIndexReference()
  public int[] getIndexCopy()
  public double getSwap()
Deep Copy   public PhasorMatrix copy()
  public Object clone()
  public static PhasorMatrix copy(PhasorMatrix aa)
Conversions   public static PhasorMatrix toPhasorRowMatrix(Phasor[] oneDarray)
  public static PhasorMatrix toPhasorRowMatrix(Complex[] oneDarray)
  public static PhasorMatrix toPhasorRowMatrix(double[] oneDarray)
  public static PhasorMatrix toPhasorColumnMatrix(Phasor[] oneDarray)
  public static PhasorMatrix toPhasorColumnMatrix(Complex[] oneDarray)
  public static PhasorMatrix toPhasorColumnMatrix(double[] oneDarray)
  public static PhasorMatrix toPhasorMatrix(ComplexMatrix cc)
  public static PhasorMatrix toPhasorMatrix(Complex[][] carray)
  public static PhasorMatrix toPhasorMatrix(Matrix marray)
  public static PhasorMatrix toPhasorMatrix(double[][] darray)
  public ComplexMatrix toComplexMatrix()
  public static ComplexMatrix toComplexMatrix(PhasorMatrix pp)
Addition   public PhasorMatrix plus(PhasorMatrix bb)
  public PhasorMatrix plus(Phasor[][] bb)
  public PhasorMatrix plus(ComplexMatrix bb)
  public PhasorMatrix plus(Complex[][] bb)
  public PhasorMatrix plus(Matrix bb)
  public PhasorMatrix plus(double[][] bb)
  public void plusEquals(PhasorMatrix bb)
  public void plusEquals(Phasor[][] bb)
  public void plusEquals(ComplexMatrix bb)
  public void plusEquals(Complex[][] bb)
  public void plusEquals(Matrix bb)
  public void plusEquals(double[][] bb)
Subtraction   public PhasorMatrix minus(PhasorMatrix bb)
  public PhasorMatrix minus(Phasor[][] bb)
  public PhasorMatrix minus(ComplexMatrix bb)
  public PhasorMatrix minus(Complex[][] bb)
  public PhasorMatrix minus(Matrix bb)
  public PhasorMatrix minus(double[][] bb)
  public void minusEquals(PhasorMatrix bb)
  public void minusEquals(Phasor[][] bb)
  public void minusEquals(ComplexMatrix bb)
  public void minusEquals(Complex[][] bb)
  public void minusEquals(Matrix bb)
  public void minusEquals(double[][] bb)
Multiplication   public PhasorMatrix times(PhasorMatrix bb)
  public PhasorMatrix times(Phasor[][] bb)
  public PhasorMatrix times(ComplexMatrix bb)
  public PhasorMatrix times(Complex[][] bb)
  public PhasorMatrix times(Matrix bb)
  public PhasorMatrix times(double[][] bb)
  public PhasorMatrix times(Phasor bb)
  public PhasorMatrix times(Complex bb)
  public PhasorMatrix times(double bb)
  public PhasorMatrix times(int bb)
  public void timesEquals(PhasorMatrix bb)
  public void timesEquals(Phasor[][] bb)
  public void timesEquals(ComplexMatrix bb)
  public void timesEquals(Complex[][] bb)
  public void timesEquals(Matrix bb)
  public void timesEquals(double[][] bb)
  public void timesEquals(Phasor bb)
  public void timesEquals(Complex bb)
  public void timesEquals(double bb)
  public void timesEquals(int bb)
Division   public PhasorMatrix over(PhasorMatrix bb)
  public PhasorMatrix over(Phasor[][] bb)
  public PhasorMatrix over(ComplexMatrix bb)
  public PhasorMatrix over(Complex[][] bb)
  public PhasorMatrix over(Matrix bb)
  public PhasorMatrix over(double[][] bb)
  public void overEquals(PhasorMatrix bb)
  public void overEquals(Phasor[][] bb)
  public void overEquals(ComplexMatrix bb)
  public void overEquals(Complex[][] bb)
  public void overEquals(Matrix bb)
  public void overEquals(double[][] bb)
Inverse   public PhasorMatrix inverse()
Transpose   public PhasorMatrix transpose()
Conjugate   public PhasorMatrix conjugate()
Adjoin   public PhasorMatrix adjoin()
Opposite   public PhasorMatrix opposite()
LU Decompostion   public PhasorMatrix luDecomp()
  public Phasor luBackSub(Phasor[] bvec)
Linear Equation
Set
  public Phasor[] solveLinearSet(Phasor[]bvec)
Trace   public Phasor trace()
Determinant   public Phasor determinant()
  public Phasor logDeterminant()
Norms   public double frobeniusNorm ()
  public double oneNorm ()
  public double infinityNorm ()


CONSTRUCTORS

public PhasorMatrix(int nrow, int ncol)
Usage:                      PhasorMatrix aa = new PhasorMatrix(nrow, ncol);
This creates a new instance of PhasorMatrix, aa, with a a nrow x ncol matrix of phasor variables and initialises all the magintudes to unity and all the phases to zero.

public PhasorMatrix(int nrow, int ncol, Phasor const)
Usage:                      PhasorMatrix aa = new PhasorMatrix(nrow, ncol, const);
This creates a new instance of PhasorMatrix, aa, with a a nrow x ncol matrix of phasor variables and initialises all the matrix elements to the phasor const.

public PhasorMatrix(Phasor[][] twoD)
Usage:                      PhasorMatrix aa = new PhasorMatrix(twoD);
This creates a new instance of PhasorMatrix, aa, with a matrix that is a reference (pointer) to the Phasor two dimensional array, twoD.
See also setTwoDarray() and copy()

public PhasorMatrix(PhasorMatrix bb)
public setElement(int i, int j, double magnitude, double phaseRad)
Usage:                      PhasorMatrix aa = new PhasorMatrix(bb);
This creates a new instance of PhasorMatrix, aa, with a matrix that is a reference (pointer) to the matrix in the existing Phasor Matrix instance bb.
See also setTwoDarray() and copy()



PUBLIC METHODS

CREATE SPECIAL MATRICES
public static PhasorMatrix.identityMatrix(int nrow)
Usage:                      aa = PhasorMatrix identityMatrix(n);
Creates an n x n phasor identity matrix (unit matrix) [all diagonal elements = 1∠0, all off-diagonal elements = 0∠0].

public static PhasorMatrix.scalarMatrix(int nrow, Phasor diagconst)
Usage:                      aa = PhasorMatrix scalarMatrix(n, diagconst);
Creates an n x n phasor scalar matrix [all diagonal elements = the same phasor (diagconst), all off-diagonal elements = 0∠0].

public static PhasorMatrix diagonalMatrix(int nrow, Phasor[] diag)
Usage:                      aa = PhasorMatrix.diagonalMatrix(n, diag);
Creates an n x n phasor diagonal matrix with the diagonal elements = the phasor array, diag, and all off-diagonal elements = 0∠0.

ROW MATRIX
public static PhasorMatrix rowMatrix(Phasor[] oneDarray)
Usage:                      aa = PhasorMatrix.rowMatrix(oneDarray);
Converts a one dimensional array, oneDarray of Phasor into a row matrix of the type PhasorMatrix.

COLUMN MATRIX
public static PhasorMatrix columnMatrix(Phasor[] oneDarray)
Usage:                      aa = PhasorMatrix.columnMatrix(oneDarray);
Converts a one dimensional array, oneDarray of Phasor into a column matrix of the type PhasorMatrix.



SET VALUES
public setTwoDarray(Phasor[][] twoD)
Usage:                      aa.setTwoDarrayl(dd);
Sets the matrix of aa with a copy of an existing nrow x ncol 2-D matrix of phasor variables, dd.

public setElement(int i, int j, Phasor aa)
public setElement(int i, int j, double magnitude, double phase)
Usage:                      aa.setElement(i, j, bb);
Sets the internal 2D array element, of matrix of aa, matrix[i][j], to a copy of the value of the Phasor() bb.
Usage:                      aa.setElement(i, j, x, y);
Sets the magintude of the internal 2D array element matrix[i][j] of matrix of aa, matrix[i][j].magnitude to x and the phase, matrix[i][j].phase, to y.

public setSubMatrix(int i, int j, Phasor[][] submat)
Usage:                      aa.setSubmatrix(i, j, submat);
Sets a sub-matrix starting with column index i, row index j to a copy of the 2D phasor array submat.

public setSubMatrix(int i, int j, int k, int l, Phasor[][] submat)
Usage:                      aa.setSubmatrix(i, j, k, l, submat);
Sets a sub-matrix starting with column index i, row index j and ending with column index k, row index l to a copy of the 2D phasor array submat. Method above does the same more conveniently. This method retained for backward compatibity.

public setSubMatrix(int[] row, int[] col, Phasor[][] submat)
Usage:                      aa.setSubMatrix(row, col, submat);
Sets a sub-matrix defined by an array of row indices, row, and an array of column indices, col, to a copy of the 2D phasor array submat



GET VALUES
public int getNrow()
Usage:                      nrow = aa.getNrow();
Returns the number of rows.

public int getNcol()
Usage:                      ncol = aa.getNcol();
Returns the number of columns.

public Phasor[][] getArrayReference()
Usage:                      xx = aa.getArrayReference();
Returns a reference (pointer) to the internal 2D array, matrix.

public Phasor[][] getArrayCopy()
Usage:                      xx = aa.getArrayReference();
Returns a copy of the internal 2D array, matrix.

public Phasor getElementReference(int i, int j)
Usage:                      xx = aa.getElementReference();
Returns a reference (pointer) to the internal 2D array element, matrix[i][j].

public Phasor getElementCopy(int i, int j)
Usage:                      xx = aa.getElementCopy();
Returns a copy of the internal 2D array element, matrix[i][j].

public PhasorMatrix getSubMatrix(int i, int j, int k, int l)
public PhasorMatrix getSubMatrix(int[] row, int[] col)
Usage:                      xx = aa.getSubMatrix(i, j, k, l);
Return a copy of the sub-matrix starting with column index i, row index j and ending with column index k, row index l.
Usage:                      xx = aa.getSubMatrix(row, col);
Return a copy of the sub-matrix defined by the array of row indices, row, and the array of column indices, col.

public int[] getIndexReference()
Usage:                      xx = aa.getIndexReference();
Returns a reference (pointer) to the internal permutation array index.

public int[] getIndexCopy()
Usage:                      xx = aa.getIndexCopy();
Returns a copy of the internal permutation array index.

public int[] getSwap()
Usage:                      x = aa.getSwap();
Returns the odd/even swap index, swap.



COPY PhasorMatrix
public PhasorMatrix copy()
public Object clone()
public static PhasorMatrix copy(PhasorMatrix aa)
Usage:                      bb = aa.copy();
Usage:                      bb = PhasorMatrix.copy(aa);
A deep copy of the PhasorMatrix instance, aa, is returned.

Clone PhasorMatrix
Usage:                      bb = (PhasorMatrix) aa.clone();
A deep copy of the PhasorMatrix instance, aa, is returned. This method overrides java.lang.Object.clone().



CONVERSIONS
Row Matrices
public static PhasorMatrix toPhasorRowMatrix(Phasor[] oneDarray)
public static PhasorMatrix toPhasorRowMatrix(Complex[] oneDarray)
public static PhasorMatrix toPhasorRowMatrix(double[] oneDarray)
Usage:                      PhasorMatrix aa = PhasorMatrix.toPhasorRowMatrix(oneDarray);
Converts a one dimensional array into a row matrix of phasors of the type PhasorMatrix. The argument, oneDarray, may be a 1-D array of Phasor, Complex or doubles.

Column Matrices
public static PhasorMatrix toPhasorColumnMatrix(Phasor[] oneDarray)
public static PhasorMatrix toPhasorColumnMatrix(Complex[] oneDarray)
public static PhasorMatrix toPhasorColumnMatrix(double[] oneDarray)
Usage:                      PhasorMatrix aa = PhasorMatrix.toPhasorColumnMatrix(oneDarray);
Converts a one dimensional array into a column matrix of phasors of the type PhasorMatrix. The argument, oneDarray, may be a 1-D array of Phasor, Complex or doubles.

Complex Matrix to Phasor Matrix
public static PhasorMatrix toPhasorMatrix(ComplexMatrix cc)
public static PhasorMatrix toPhasorMatrix(Complex[][] carray)
Usage:                      PhasorMatrix aa = PhasorMatrix.toPhasorMatrix(bb);
Converts the argument bb to a PhasorMatrix. The argument, bb, may be ComplexMatrix or a 2-D array of Complex.

Real Matrix to Phasor Matrix
public static PhasorMatrix toPhasorMatrix(Matrix marray)
public static PhasorMatrix toPhasorMatrix(double[][] darray)
Usage:                      PhasorMatrix aa = PhasorMatrix.toPhasorMatrix(bb);
Converts the argument bb to a PhasorMatrix. The argument, bb, may be Matrix or a 2-D array of doubles.

Phasor Matrix to Complex Matrix
public ComplexMatrix toComplexMatrix()
public static ComplexMatrix toComplexMatrix(PhasorMatrix pp)
Usage:                      ComplexMatrix aa = bb.toComplex();
Usage:                      ComplexMatrix aa = PhasorMatrix.toComplex(bb);
Converts a PhasorMatrix (argument bb) to a ComplexMatrix, aa.



ADDITION
public PhasorMatrix plus(PhasorMatrix bb)
public PhasorMatrix plus(Phasor[][] bb)
public PhasorMatrix plus(ComplexMatrix bb)
public PhasorMatrix plus(Complex[][] bb)
public PhasorMatrix plus(Matrix bb)
public PhasorMatrix plus(double[][] bb)
Usage:                      cc = aa.plus(bb);
Performs the operation cc = aa + bb where aa and cc are PhasorMatrix and bb may be a PhasorMatrix, a complex matrix (ComplexMatrix), a real matrix (Matrix), a 2-D Phasor array, a 2-D array of Complex or a 2-D array of doubles.

Equivalence of the += operator
public void plusEquals(PhasorMatrix bb)
public void plusEquals(Phasor[][] bb)
public void plusEquals(ComplexMatrix bb)
public void plusEquals(Complex[][] bb)
public void plusEquals(Matrix bb)
public void plusEquals(double[][] bb)
Usage:                      aa.plusEquals(bb);
Performs the operation aa = aa + bb where aa is a PhasorMatrix and bb may be a PhasorMatrix, a complex matrix (ComplexMatrix), a real matrix (Matrix), a 2-D Phasor array, a 2-D array of Complex or a 2-D array of doubles.



SUBTRACTION
public PhasorMatrix minus(PhasorMatrix bb)
public PhasorMatrix minus(Phasor[][] bb)
public PhasorMatrix minus(ComplexMatrix bb)
public PhasorMatrix minus(Complex[][] bb)
public PhasorMatrix minus(Matrix bb)
public PhasorMatrix minus(double[][] bb)
public static PhasorMatrix minus(PhasorMatrix aa, PhasorMatrix bb)
Usage:                      cc = aa.minus(bb);
Performs the operation cc = aa - bb where aa and cc are PhasorMatrix and bb may be PhasorMatrix, a real Matrix, a 2-D Phasor array or a 2-D array of doubles.

Equivalence of the −= operator
public void minusEquals(PhasorMatrix bb)
public void minusEquals(Phasor[][] bb)
public void minusEquals(ComplexMatrix bb)
public void minusEquals(Complex[][] bb)
public void minusEquals(Matrix bb)
public void minusEquals(double[][] bb)
Usage:                      aa.plusEquals(bb);
Performs the operation aa = aa - bb where aa is a PhasorMatrix and bb may be a PhasorMatrix, a complex matrix (ComplexMatrix), a real matrix (Matrix), a 2-D Phasor array, a 2-D array of Complex or a 2-D array of doubles.



MULTIPLICATION
public PhasorMatrix times(PhasorMatrix bb)
public PhasorMatrix times(Phasor[][] bb)
public PhasorMatrix times(ComplexMatrix bb)
public PhasorMatrix times(Complex[][] bb)
public PhasorMatrix times(Matrix bb)
public PhasorMatrix times(double[][] bb)
public PhasorMatrix times(Phasor bb)
public PhasorMatrix times(Complex bb)
public PhasorMatrix times(double bb)
public PhasorMatrix times(int bb)
Usage:                      cc = aa.times(bb);
Performs the operation cc = aa*bb where aa and cc are PhasorMatrix and bb may be a PhasorMatrix, a complex matrix (ComplexMatrix), a real matrix (Matrix), a 2-D Phasor array, a 2-D array of Complex, a 2-D array of doubles, a single Phasor, a single Complex, a single double or a single integer (int).

Equivalence of the *= operator
public void timesEquals(PhasorMatrix bb)
public void timesEquals(Phasor[][] bb)
public void timesEquals(ComplexMatrix bb)
public void timesEquals(Complex[][] bb)
public void timesEquals(Matrix bb)
public void timesEquals(double[][] bb)
public void timesEquals(Phasor bb)
public void timesEquals(Complex bb)
public void timesEquals(double bb)
public void timesEquals(int bb)
Usage:                      aa.plusEquals(bb);
Performs the operation aa = aa*bb where aa is a PhasorMatrix and bb may be a PhasorMatrix, a complex matrix (ComplexMatrix), a real matrix (Matrix), a 2-D Phasor array, a 2-D array of Complex, a 2-D array of doubles, a single Phasor, a single Complex, a single double or a single integer (int).



DIVISION
public PhasorMatrix over(PhasorMatrix bb)
public PhasorMatrix over(Phasor[][] bb)
public PhasorMatrix over(ComplexMatrix bb)
public PhasorMatrix over(Complex[][] bb)
public PhasorMatrix over(Matrix bb)
public PhasorMatrix over(double[][] bb)
Usage:                      cc = aa.over(bb);
Performs the operation cc = aa/bb where aa and cc are PhasorMatrix and bb may be PhasorMatrix, a ComplexMatrix, a real Matrix, a 2-D Phasor array or a 2-D array of doubles. This method first converts bb to a PhasorMatrix and returns the product of the PhasorMatrix aa and the inverse of the PhasorMatrix transform of bb.

Equivalence of the /= operator
public void overEquals(PhasorMatrix bb)
public void overEquals(Phasor[][] bb)
public void overEquals(ComplexMatrix bb)
public void overEquals(Complex[][] bb)
public void overEquals(Matrix bb)
public void overEquals(double[][] bb)
Usage:                      aa.plusEquals(bb);
Performs the operation aa = aa/bb where aa is a PhasorMatrix and bb may be a PhasorMatrix, a complex matrix (ComplexMatrix), a real matrix (Matrix), a 2-D Phasor array, a 2-D array of Complex or a 2-D array of doubles This method first converts bb to a PhasorMatrix and returns the product of the PhasorMatrix aa and the inverse of the PhasorMatrix transform of bb.



INVERSE
public PhasorMatrix inverse()
Usage:                      bb = aa.inverse();
Returns the inverse of a phasor square matrix, aa.



TRANSPOSE
public PhasorMatrix transpose()
Usage:                      bb = aa.transpose();
Returns the transpose of a phasor square matrix, aa.



CONJUGATE
public PhasorMatrix conjugatr()
Usage:                      bb = aa.conjugate();
Returns the phasor conjugate matrix of a phasor matrix, aa.



ADJOIN
public PhasorMatrix adjoin()
Usage:                      bb = aa.adjoin();
Returns the adjoin of a phasor matrix, aa.



OPPOSITE
public PhasorMatrix opposite()
Usage:                      bb = aa.opposite();
Returns the opposite of a phasor matrix, aa.



LU DECOMPOSITION
public PhasorMatrix luDecomp()
Usage:                      lu = aa.luDecomp();
Returns the phasor LU decomposition of a phasor matrix, aa.
See Numerical Recipes, The Art of Scientific Computing by W H Press, S A Teukolsky, W T Vetterling & B P Flannery, Cambridge University Press, http://www.nr.com/, for details of the LU decomposition. This method mimics their C language function for real numbers.
int[] index stores of row permutations.
double dswap is assigned +1.0 for even number of row interchanges or -1.0 for odd number of row interchanges.

public Phasor luBackSub(Phasor[] bvec)
Usage:                      xx = lu.luDecomp(bb);
The forward and backward substitution procedure associated with the phasor LU decompostion when used to solves the linear set of phasor equations A.x = b. luBackSub actually solves L.x = b where L is the phasor LU decompostion of A (lu above) obtained from luDecomp(), b is bb above and x is bb above. See solveLinearSet() for its use in solving the equations A.x = b.



SOLUTION OF A SET OF LINEAR EQUATIONS
public Phasor solveLinearSet(Phasor[] b)
Usage:                      x = a.solveLinearSet(b);
Solves the linear set of phasor equations A.x = b where A is the matrix of phasor coefficients, b is the right-hand side phasor vector and x is the phasor vector of solution values. This method uses an LU decomposition [luDecomp() and luBackSub() - see above].



TRACE
public Phasor trace()
Usage:                      b = aa.trace();




DETERMINANT
public Phasor determinant()
Usage:                      b = aa.determinant();
Returns the determinant of a phasor square matrix, aa.

public Phasor logDeterminant()
Usage:                      b = aa.logDeterminant();
Returns the natural logarithm of the determinant of a phasor square matrix, aa. Useful if determinant() underflows or overflows.



NORMS
public double frobeniusNorm ()
Usage:                      b = aa.frobeniusNorm();
Returns the Frobenius Norm (Euclidian Norm) of a phasor matrix, aa.

public double oneNorm ()
Usage:                      b = aa.oneNorm();
Returns the One Norm of a phasor matrix, aa.

public double infinityNorm ()
Usage:                      b = aa.infinityNorm();
Returns the Infinity Norm of a phasor matrix, aa.



OTHER CLASSES USED BY THIS CLASS

This class uses the following classes in this library:



This page was prepared by Dr Michael Thomas Flanagan