JSci.maths.matrices.ComplexTridiagonalMatrix.vm Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsci Show documentation
Show all versions of jsci Show documentation
JSci is a set of open source Java packages. The aim is to encapsulate scientific methods/principles in the most natural way possible. As such they should greatly aid the development of scientific based software.
It offers: abstract math interfaces, linear algebra (support for various matrix and vector types), statistics (including probability distributions), wavelets, newtonian mechanics, chart/graph components (AWT and Swing), MathML DOM implementation, ...
Note: some packages, like javax.comm, for the astro and instruments package aren't listed as dependencies (not available).
The newest version!
/* AUTO-GENERATED */
package JSci.maths.matrices;
import JSci.maths.ArrayMath;
import JSci.maths.Complex;
import JSci.maths.ComplexMapping;
import JSci.maths.LinearMath;
import JSci.maths.DimensionException;
import JSci.maths.MaximumIterationsExceededException;
import JSci.maths.vectors.AbstractComplexVector;
import JSci.maths.vectors.ComplexVector;
/**
* The ComplexTridiagonalMatrix class provides an object for encapsulating tridiagonal matrices containing complex numbers.
* Uses compressed diagonal storage.
* @version 2.2
* @author Mark Hale
*/
public class ComplexTridiagonalMatrix extends AbstractComplexSquareMatrix implements TridiagonalMatrix {
/**
* Tridiagonal data.
*/
protected final double ldiagRe[],ldiagIm[];
protected final double diagRe[],diagIm[];
protected final double udiagRe[],udiagIm[];
/**
* Constructs an empty matrix.
* @param size the number of rows/columns
*/
public ComplexTridiagonalMatrix(final int size) {
super(size);
ldiagRe=new double[size];
ldiagIm=new double[size];
diagRe=new double[size];
diagIm=new double[size];
udiagRe=new double[size];
udiagIm=new double[size];
}
/**
* Constructs a matrix from an array.
* Any non-tridiagonal elements in the array are ignored.
* @param array an assigned value
* @exception MatrixDimensionException If the array is not square.
*/
public ComplexTridiagonalMatrix(final Complex array[][]) {
this(array.length);
if(!ArrayMath.isSquare(array))
throw new MatrixDimensionException("Array is not square.");
diagRe[0]=array[0][0].real();
diagIm[0]=array[0][0].imag();
udiagRe[0]=array[0][1].real();
udiagIm[0]=array[0][1].imag();
int i=1;
for(;i=0 && i=0 && j=0 && i=0 && j=0 && i=0 && j=0 && i=0 && j=0 && i=0 && j-norm.
* @author Taber Smith
*/
public double infNorm() {
double result = Math.sqrt(#modSqrA("diag" "[0]")) + Math.sqrt(#modSqrA("udiag" "[0]"));
double tmpResult;
int i=1;
for(;iresult)
result=tmpResult;
}
tmpResult = Math.sqrt(#modSqrA("ldiag" "[i]")) + Math.sqrt(#modSqrA("diag" "[i]"));
if(tmpResult>result)
result=tmpResult;
return result;
}
/**
* Returns the Frobenius (l2) norm.
* @author Taber Smith
*/
public double frobeniusNorm() {
double result=diagRe[0]*diagRe[0]+diagIm[0]*diagIm[0]+
udiagRe[0]*udiagRe[0]+udiagIm[0]*udiagIm[0];
int i=1;
for(;i3) {
arrayRe[1][0]=#multAARe("ldiag" "[1]" "m.diag" "[0]")+#multAARe("diag" "[1]" "m.ldiag" "[1]");
arrayIm[1][0]=#multAAIm("ldiag" "[1]" "m.diag" "[0]")+#multAAIm("diag" "[1]" "m.ldiag" "[1]");
arrayRe[1][1]=#multAARe("ldiag" "[1]" "m.udiag" "[0]")+#multAARe("diag" "[1]" "m.diag" "[1]")+#multAARe("udiag" "[1]" "m.ldiag" "[2]");
arrayIm[1][1]=#multAAIm("ldiag" "[1]" "m.udiag" "[0]")+#multAAIm("diag" "[1]" "m.diag" "[1]")+#multAAIm("udiag" "[1]" "m.ldiag" "[2]");
arrayRe[1][2]=#multAARe("diag" "[1]" "m.udiag" "[1]")+#multAARe("udiag" "[1]" "m.diag" "[2]");
arrayIm[1][2]=#multAAIm("diag" "[1]" "m.udiag" "[1]")+#multAAIm("udiag" "[1]" "m.diag" "[2]");
arrayRe[1][3]=#multAARe("udiag" "[1]" "m.udiag" "[2]");
arrayIm[1][3]=#multAAIm("udiag" "[1]" "m.udiag" "[2]");
}
if(mRow==3) {
arrayRe[1][0]=#multAARe("ldiag" "[1]" "m.diag" "[0]")+#multAARe("diag" "[1]" "m.ldiag" "[1]");
arrayIm[1][0]=#multAAIm("ldiag" "[1]" "m.diag" "[0]")+#multAAIm("diag" "[1]" "m.ldiag" "[1]");
arrayRe[1][1]=#multAARe("ldiag" "[1]" "m.udiag" "[0]")+#multAARe("diag" "[1]" "m.diag" "[1]")+#multAARe("udiag" "[1]" "m.ldiag" "[2]");
arrayIm[1][1]=#multAAIm("ldiag" "[1]" "m.udiag" "[0]")+#multAAIm("diag" "[1]" "m.diag" "[1]")+#multAAIm("udiag" "[1]" "m.ldiag" "[2]");
arrayRe[1][2]=#multAARe("diag" "[1]" "m.udiag" "[1]")+#multAARe("udiag" "[1]" "m.diag" "[2]");
arrayIm[1][2]=#multAAIm("diag" "[1]" "m.udiag" "[1]")+#multAAIm("udiag" "[1]" "m.diag" "[2]");
} else if(mRow>4) {
for(int i=2;i3) {
arrayRe[mRow-2][mRow-4]=#multAARe("ldiag" "[mRow-2]" "m.ldiag" "[mRow-3]");
arrayIm[mRow-2][mRow-4]=#multAAIm("ldiag" "[mRow-2]" "m.ldiag" "[mRow-3]");
arrayRe[mRow-2][mRow-3]=#multAARe("ldiag" "[mRow-2]" "m.diag" "[mRow-3]")+#multAARe("diag" "[mRow-2]" "m.ldiag" "[mRow-2]");
arrayIm[mRow-2][mRow-3]=#multAAIm("ldiag" "[mRow-2]" "m.diag" "[mRow-3]")+#multAAIm("diag" "[mRow-2]" "m.ldiag" "[mRow-2]");
arrayRe[mRow-2][mRow-2]=#multAARe("ldiag" "[mRow-2]" "m.udiag" "[mRow-3]")+#multAARe("diag" "[mRow-2]" "m.diag" "[mRow-2]")+#multAARe("udiag" "[mRow-2]" "m.ldiag" "[mRow-1]");
arrayIm[mRow-2][mRow-2]=#multAAIm("ldiag" "[mRow-2]" "m.udiag" "[mRow-3]")+#multAAIm("diag" "[mRow-2]" "m.diag" "[mRow-2]")+#multAAIm("udiag" "[mRow-2]" "m.ldiag" "[mRow-1]");
arrayRe[mRow-2][mRow-1]=#multAARe("diag" "[mRow-2]" "m.udiag" "[mRow-2]")+#multAARe("udiag" "[mRow-2]" "m.diag" "[mRow-1]");
arrayIm[mRow-2][mRow-1]=#multAAIm("diag" "[mRow-2]" "m.udiag" "[mRow-2]")+#multAAIm("udiag" "[mRow-2]" "m.diag" "[mRow-1]");
}
mRow--;
arrayRe[mRow][mRow-2]=#multAARe("ldiag" "[mRow]" "m.ldiag" "[mRow-1]");
arrayIm[mRow][mRow-2]=#multAAIm("ldiag" "[mRow]" "m.ldiag" "[mRow-1]");
arrayRe[mRow][mRow-1]=#multAARe("ldiag" "[mRow]" "m.diag" "[mRow-1]")+#multAARe("diag" "[mRow]" "m.ldiag" "[mRow]");
arrayIm[mRow][mRow-1]=#multAAIm("ldiag" "[mRow]" "m.diag" "[mRow-1]")+#multAAIm("diag" "[mRow]" "m.ldiag" "[mRow]");
arrayRe[mRow][mRow]=#multAARe("ldiag" "[mRow]" "m.udiag" "[mRow-1]")+#multAARe("diag" "[mRow]" "m.diag" "[mRow]");
arrayIm[mRow][mRow]=#multAAIm("ldiag" "[mRow]" "m.udiag" "[mRow-1]")+#multAAIm("diag" "[mRow]" "m.diag" "[mRow]");
return new ComplexSquareMatrix(arrayRe,arrayIm);
} else
throw new MatrixDimensionException("Incompatible matrices.");
}
private ComplexSquareMatrix multiplyTridiagonal(final AbstractComplexSquareMatrix m) {
int mRow=numRows;
if(numCols==m.rows()) {
final double arrayRe[][]=new double[mRow][mRow];
final double arrayIm[][]=new double[mRow][mRow];
Complex elem1,elem2,elem3;
elem1=m.getElement(0,0);elem2=m.getElement(1,0);
arrayRe[0][0]=#multAZRe("diag" "[0]" "elem1")+#multAZRe("udiag" "[0]" "elem2");
arrayIm[0][0]=#multAZIm("diag" "[0]" "elem1")+#multAZIm("udiag" "[0]" "elem2");
elem1=m.getElement(0,1);elem2=m.getElement(1,1);
arrayRe[0][1]=#multAZRe("diag" "[0]" "elem1")+#multAZRe("udiag" "[0]" "elem2");
arrayIm[0][1]=#multAZIm("diag" "[0]" "elem1")+#multAZIm("udiag" "[0]" "elem2");
elem1=m.getElement(1,2);
arrayRe[0][2]=#multAZRe("udiag" "[0]" "elem1");
arrayIm[0][2]=#multAZIm("udiag" "[0]" "elem1");
if(mRow>3) {
elem1=m.getElement(0,0);elem2=m.getElement(1,0);
arrayRe[1][0]=#multAZRe("ldiag" "[1]" "elem1")+#multAZRe("diag" "[1]" "elem2");
arrayIm[1][0]=#multAZIm("ldiag" "[1]" "elem1")+#multAZIm("diag" "[1]" "elem2");
elem1=m.getElement(0,1);elem2=m.getElement(1,1);elem3=m.getElement(2,1);
arrayRe[1][1]=#multAZRe("ldiag" "[1]" "elem1")+#multAZRe("diag" "[1]" "elem2")+#multAZRe("udiag" "[1]" "elem3");
arrayIm[1][1]=#multAZIm("ldiag" "[1]" "elem1")+#multAZIm("diag" "[1]" "elem2")+#multAZIm("udiag" "[1]" "elem3");
elem1=m.getElement(1,2);elem2=m.getElement(2,2);
arrayRe[1][2]=#multAZRe("diag" "[1]" "elem1")+#multAZRe("udiag" "[1]" "elem2");
arrayIm[1][2]=#multAZIm("diag" "[1]" "elem1")+#multAZIm("udiag" "[1]" "elem2");
elem1=m.getElement(2,3);
arrayRe[1][3]=#multAZRe("udiag" "[1]" "elem1");
arrayIm[1][3]=#multAZIm("udiag" "[1]" "elem1");
}
if(mRow==3) {
elem1=m.getElement(0,0);elem2=m.getElement(1,0);
arrayRe[1][0]=#multAZRe("ldiag" "[1]" "elem1")+#multAZRe("diag" "[1]" "elem2");
arrayIm[1][0]=#multAZIm("ldiag" "[1]" "elem1")+#multAZIm("diag" "[1]" "elem2");
elem1=m.getElement(0,1);elem2=m.getElement(1,1);elem3=m.getElement(2,1);
arrayRe[1][1]=#multAZRe("ldiag" "[1]" "elem1")+#multAZRe("diag" "[1]" "elem2")+#multAZRe("udiag" "[1]" "elem3");
arrayIm[1][1]=#multAZIm("ldiag" "[1]" "elem1")+#multAZIm("diag" "[1]" "elem2")+#multAZIm("udiag" "[1]" "elem3");
elem1=m.getElement(1,2);elem2=m.getElement(2,2);
arrayRe[1][2]=#multAZRe("diag" "[1]" "elem1")+#multAZRe("udiag" "[1]" "elem2");
arrayIm[1][2]=#multAZIm("diag" "[1]" "elem1")+#multAZIm("udiag" "[1]" "elem2");
} else if(mRow>4) {
for(int i=2;i3) {
elem1=m.getElement(mRow-3,mRow-4);
arrayRe[mRow-2][mRow-4]=#multAZRe("ldiag" "[mRow-2]" "elem1");
arrayIm[mRow-2][mRow-4]=#multAZIm("ldiag" "[mRow-2]" "elem1");
elem1=m.getElement(mRow-3,mRow-3);elem2=m.getElement(mRow-2,mRow-3);
arrayRe[mRow-2][mRow-3]=#multAZRe("ldiag" "[mRow-2]" "elem1")+#multAZRe("diag" "[mRow-2]" "elem2");
arrayIm[mRow-2][mRow-3]=#multAZIm("ldiag" "[mRow-2]" "elem1")+#multAZIm("diag" "[mRow-2]" "elem2");
elem1=m.getElement(mRow-3,mRow-2);elem2=m.getElement(mRow-2,mRow-2);elem3=m.getElement(mRow-1,mRow-2);
arrayRe[mRow-2][mRow-2]=#multAZRe("ldiag" "[mRow-2]" "elem1")+#multAZRe("diag" "[mRow-2]" "elem2")+#multAZRe("udiag" "[mRow-2]" "elem3");
arrayIm[mRow-2][mRow-2]=#multAZIm("ldiag" "[mRow-2]" "elem1")+#multAZIm("diag" "[mRow-2]" "elem2")+#multAZIm("udiag" "[mRow-2]" "elem3");
elem1=m.getElement(mRow-2,mRow-1);elem2=m.getElement(mRow-1,mRow-1);
arrayRe[mRow-2][mRow-1]=#multAZRe("diag" "[mRow-2]" "elem1")+#multAZRe("udiag" "[mRow-2]" "elem2");
arrayIm[mRow-2][mRow-1]=#multAZIm("diag" "[mRow-2]" "elem1")+#multAZIm("udiag" "[mRow-2]" "elem2");
}
mRow--;
elem1=m.getElement(mRow-1,mRow-2);
arrayRe[mRow][mRow-2]=#multAZRe("ldiag" "[mRow]" "elem1");
arrayIm[mRow][mRow-2]=#multAZIm("ldiag" "[mRow]" "elem1");
elem1=m.getElement(mRow-1,mRow-1);elem2=m.getElement(mRow,mRow-1);
arrayRe[mRow][mRow-1]=#multAZRe("ldiag" "[mRow]" "elem1")+#multAZRe("diag" "[mRow]" "elem2");
arrayIm[mRow][mRow-1]=#multAZIm("ldiag" "[mRow]" "elem1")+#multAZIm("diag" "[mRow]" "elem2");
elem1=m.getElement(mRow-1,mRow);elem2=m.getElement(mRow,mRow);
arrayRe[mRow][mRow]=#multAZRe("ldiag" "[mRow]" "elem1")+#multAZRe("diag" "[mRow]" "elem2");
arrayIm[mRow][mRow]=#multAZIm("ldiag" "[mRow]" "elem1")+#multAZIm("diag" "[mRow]" "elem2");
return new ComplexSquareMatrix(arrayRe,arrayIm);
} else {
throw new MatrixDimensionException("Incompatible matrices.");
}
}
// HERMITIAN ADJOINT
/**
* Returns the hermitian adjoint of this matrix.
* @return a complex tridiagonal matrix
*/
public AbstractComplexMatrix hermitianAdjoint() {
int mRow=numRows;
final ComplexTridiagonalMatrix ans=new ComplexTridiagonalMatrix(mRow);
System.arraycopy(ldiagRe,1,ans.udiagRe,0,ldiagRe.length-1);
System.arraycopy(diagRe,0,ans.diagRe,0,diagRe.length);
System.arraycopy(udiagRe,0,ans.ldiagRe,1,udiagRe.length-1);
ans.diagIm[0]=-diagIm[0];
ans.ldiagIm[1]=-udiagIm[0];
mRow--;
for(int i=1;i