use of org.ojalgo.matrix.store.ComplexDenseStore in project ojAlgo by optimatika.
the class EigenvalueTest method testPaulsMathNote.
@Test
public void testPaulsMathNote() {
final double[][] tmpData = new double[][] { { 3, -9 }, { 4, -3 } };
final PrimitiveDenseStore tmpA = PrimitiveDenseStore.FACTORY.rows(tmpData);
final int tmpLength = tmpData.length;
final Array1D<ComplexNumber> tmpExpVals = Array1D.COMPLEX.makeZero(2);
tmpExpVals.set(0, ComplexNumber.of(0.0, THREE * SQRT.invoke(THREE)));
tmpExpVals.set(1, tmpExpVals.get(0).conjugate());
final Array2D<ComplexNumber> tmpExpVecs = Array2D.COMPLEX.makeZero(2, 2);
tmpExpVecs.set(0, 0, ComplexNumber.of(THREE, ZERO));
tmpExpVecs.set(1, 0, ComplexNumber.of(ONE, -SQRT.invoke(THREE)));
tmpExpVecs.set(0, 1, ComplexNumber.of(THREE, ZERO));
tmpExpVecs.set(1, 1, ComplexNumber.of(ONE, SQRT.invoke(THREE)));
final Eigenvalue<Double> tmpEvD = Eigenvalue.PRIMITIVE.make(tmpA, false);
tmpEvD.decompose(tmpA);
final MatrixStore<Double> tmpD = tmpEvD.getD();
final MatrixStore<Double> tmpV = tmpEvD.getV();
final Array1D<ComplexNumber> tmpValues = tmpEvD.getEigenvalues();
final MatrixStore<ComplexNumber> tmpVectors = tmpEvD.getEigenvectors();
TestUtils.assertEquals(tmpExpVals, tmpValues);
for (int j = 0; j < tmpLength; j++) {
final Array1D<ComplexNumber> tmpSliceColumn = tmpExpVecs.sliceColumn(0, j);
final Access1D<ComplexNumber> tmpActual = tmpVectors.sliceColumn(0, j);
final ComplexNumber tmpFactor = tmpActual.get(0).divide(tmpSliceColumn.get(0));
TestUtils.assertEquals(tmpSliceColumn.get(1).multiply(tmpFactor), tmpActual.get(1));
}
final ComplexDenseStore tmpCmplA = ComplexDenseStore.FACTORY.copy(tmpA);
final ComplexDenseStore tmpCmplD = ComplexDenseStore.FACTORY.copy(tmpD);
final ComplexDenseStore tmpCmplV = ComplexDenseStore.FACTORY.copy(tmpV);
final MatrixStore<ComplexNumber> tmpExp1 = tmpCmplA.multiply(tmpCmplV);
final MatrixStore<ComplexNumber> tmpAct1 = tmpCmplV.multiply(tmpCmplD);
TestUtils.assertEquals(tmpExp1, tmpAct1);
final ComplexDenseStore tmpComplexD = ComplexDenseStore.FACTORY.makeZero(tmpLength, tmpLength);
for (int j = 0; j < tmpLength; j++) {
tmpComplexD.set(j, j, tmpValues.get(j));
}
final MatrixStore<ComplexNumber> tmpExp2 = tmpCmplA.multiply(tmpVectors);
final MatrixStore<ComplexNumber> tmpAct2 = tmpVectors.multiply(tmpComplexD);
TestUtils.assertEquals(tmpExp2, tmpAct2);
tmpEvD.computeValuesOnly(tmpA);
final Array1D<ComplexNumber> tmpEigenvaluesOnly = tmpEvD.getEigenvalues();
TestUtils.assertEquals(tmpValues, tmpEigenvaluesOnly);
}
use of org.ojalgo.matrix.store.ComplexDenseStore in project ojAlgo by optimatika.
the class EigenvalueTest method testPrimitiveAsComplex.
@Test
public void testPrimitiveAsComplex() {
final double[][] tmpData = new double[][] { { 1, 0, 3 }, { 0, 4, 1 }, { -5, 1, 0 } };
final PrimitiveDenseStore tmpA = PrimitiveDenseStore.FACTORY.rows(tmpData);
final int tmpLength = tmpData.length;
final Eigenvalue<Double> tmpEvD = Eigenvalue.PRIMITIVE.make(tmpA, false);
tmpEvD.decompose(tmpA);
final MatrixStore<Double> tmpD = tmpEvD.getD();
final MatrixStore<Double> tmpV = tmpEvD.getV();
final Array1D<ComplexNumber> tmpValues = tmpEvD.getEigenvalues();
final MatrixStore<ComplexNumber> tmpVectors = tmpEvD.getEigenvectors();
final ComplexDenseStore tmpCmplA = ComplexDenseStore.FACTORY.copy(tmpA);
final ComplexDenseStore tmpCmplD = ComplexDenseStore.FACTORY.copy(tmpD);
final ComplexDenseStore tmpCmplV = ComplexDenseStore.FACTORY.copy(tmpV);
final MatrixStore<ComplexNumber> tmpExp1 = tmpCmplA.multiply(tmpCmplV);
final MatrixStore<ComplexNumber> tmpAct1 = tmpCmplV.multiply(tmpCmplD);
TestUtils.assertEquals(tmpExp1, tmpAct1);
final ComplexDenseStore tmpAltD = ComplexDenseStore.FACTORY.makeZero(tmpLength, tmpLength);
final MatrixStore<ComplexNumber> tmpAltV = tmpVectors;
for (int j = 0; j < tmpLength; j++) {
tmpAltD.set(j, j, tmpValues.get(j));
}
final MatrixStore<ComplexNumber> tmpExp2 = tmpCmplA.multiply(tmpAltV);
final MatrixStore<ComplexNumber> tmpAct2 = tmpAltV.multiply(tmpAltD);
TestUtils.assertEquals(tmpExp2, tmpAct2);
tmpEvD.computeValuesOnly(tmpA);
final Array1D<ComplexNumber> tmpEigenvaluesOnly = tmpEvD.getEigenvalues();
TestUtils.assertEquals(tmpValues, tmpEigenvaluesOnly);
}
Aggregations