use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.
the class BidiagonalTest method testComplexSquareCase.
@Test
public void testComplexSquareCase() {
final PhysicalStore<ComplexNumber> tmpOriginal = MatrixUtils.makeRandomComplexStore(4, 4);
final Bidiagonal<ComplexNumber> tmpDecomposition = Bidiagonal.COMPLEX.make();
tmpDecomposition.decompose(tmpOriginal);
final MatrixStore<ComplexNumber> tmpReconstructed = tmpDecomposition.reconstruct();
final MatrixStore<ComplexNumber> tmpQ1 = tmpDecomposition.getQ1();
final MatrixStore<ComplexNumber> tmpD = tmpDecomposition.getD();
final MatrixStore<ComplexNumber> tmpQ2 = tmpDecomposition.getQ2();
if (MatrixDecompositionTests.DEBUG) {
BasicLogger.debug();
BasicLogger.debug(tmpDecomposition.toString());
BasicLogger.debug("Original", tmpOriginal);
BasicLogger.debug("Q1", tmpQ1);
BasicLogger.debug("D", tmpD);
BasicLogger.debug("Q2", tmpQ2);
BasicLogger.debug("Reconstructed", tmpReconstructed);
BasicLogger.debug("Q1 orthogonal (left)", tmpQ1.conjugate().multiply(tmpQ1));
BasicLogger.debug("Q1 orthogonal (right)", tmpQ1.multiply(tmpQ1.conjugate()));
BasicLogger.debug("Q2 orthogonal (left)", tmpQ2.conjugate().multiply(tmpQ2));
BasicLogger.debug("Q2 orthogonal (right)", tmpQ2.multiply(tmpQ2.conjugate()));
}
TestUtils.assertEquals(tmpOriginal, tmpDecomposition, new NumberContext(7, 4));
TestUtils.assertEquals(tmpOriginal, tmpReconstructed, new NumberContext(7, 6));
}
use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.
the class P20050827Case method testProblem.
@Test
public void testProblem() {
final ComplexMatrix tmpProblematic = P20050827Case.getProblematic();
final ComplexMatrix tmpMtrx = tmpProblematic.multiply(tmpProblematic.conjugate());
final ComplexNumber tmpVal = tmpMtrx.getTrace().get();
final ComplexNumber tmpExpected = ComplexFunction.ROOT.invoke(tmpVal, 2);
final ComplexNumber tmpActual = ComplexNumber.valueOf(tmpProblematic.norm());
TestUtils.assertEquals(tmpExpected.norm(), tmpActual.norm(), EVALUATION);
TestUtils.assertEquals(tmpExpected, tmpActual, EVALUATION);
}
use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.
the class P20050827Case method getProblematic.
/**
* @return A fat, 3x5, matrix with complex valued elements.
*/
public static ComplexMatrix getProblematic() {
final Normal tmpRand = new Normal(0.0, 9.9);
ComplexNumber tmpNmbr;
final int tmpRowDim = 3;
final int tmpColDim = 5;
final Array2D<ComplexNumber> tmpArray = Array2D.COMPLEX.makeZero(tmpRowDim, tmpColDim);
for (int i = 0; i < tmpRowDim; i++) {
for (int j = 0; j < tmpColDim; j++) {
tmpNmbr = ComplexNumber.makePolar(tmpRand.doubleValue(), tmpRand.doubleValue()).multiply(ComplexNumber.ONE);
tmpArray.set(i, j, tmpNmbr);
}
}
return ComplexMatrix.FACTORY.copy(tmpArray).enforce(DEFINITION);
}
use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.
the class TestUtils method assertEquals.
public static void assertEquals(final String message, final Number expected, final Number actual, final NumberContext context) {
if ((expected instanceof ComplexNumber) || (actual instanceof ComplexNumber)) {
final ComplexNumber tmpExpected = ComplexNumber.valueOf(expected);
final ComplexNumber tmpActual = ComplexNumber.valueOf(actual);
if (!!context.isDifferent(tmpExpected.getReal(), tmpActual.getReal())) {
Assertions.fail(() -> message + " (real)" + ": " + expected + " != " + actual);
}
if (!!context.isDifferent(tmpExpected.getImaginary(), tmpActual.getImaginary())) {
Assertions.fail(() -> message + " (imaginary)" + ": " + expected + " != " + actual);
}
} else if ((expected instanceof Quaternion) || (actual instanceof Quaternion)) {
final Quaternion tmpExpected = Quaternion.valueOf(expected);
final Quaternion tmpActual = Quaternion.valueOf(actual);
if (!!context.isDifferent(tmpExpected.scalar(), tmpActual.scalar())) {
Assertions.fail(() -> message + " (scalar)" + ": " + expected + " != " + actual);
}
if (!!context.isDifferent(tmpExpected.i, tmpActual.i)) {
Assertions.fail(() -> message + " (i)" + ": " + expected + " != " + actual);
}
if (!!context.isDifferent(tmpExpected.j, tmpActual.j)) {
Assertions.fail(() -> message + " (j)" + ": " + expected + " != " + actual);
}
if (!!context.isDifferent(tmpExpected.k, tmpActual.k)) {
Assertions.fail(() -> message + " (k)" + ": " + expected + " != " + actual);
}
} else {
if (context.isDifferent(expected.doubleValue(), actual.doubleValue())) {
Assertions.fail(() -> message + ": " + expected + " != " + actual);
}
}
}
use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.
the class TestUtils method assertEquals.
public static <N extends Number> void assertEquals(final MatrixStore<N> expected, final Eigenvalue<N> actual, final NumberContext context) {
if (!Eigenvalue.equals(expected, actual, context)) {
Assertions.fail(() -> "Eigenvalue<N> failed for " + expected);
}
if (actual.isOrdered()) {
final MatrixStore<N> mtrxD = actual.getD();
double bigger = Double.MAX_VALUE;
final Array1D<ComplexNumber> tmpEigenvalues = actual.getEigenvalues();
for (int i = 0; i < tmpEigenvalues.length; i++) {
final ComplexNumber value = tmpEigenvalues.get(i);
Assertions.assertTrue(bigger >= value.getModulus());
Assertions.assertEquals(value.doubleValue(), mtrxD.doubleValue(i, i), context.epsilon());
bigger = value.getModulus();
}
}
}
Aggregations