Search in sources :

Example 41 with ComplexNumber

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));
}
Also used : NumberContext(org.ojalgo.type.context.NumberContext) ComplexNumber(org.ojalgo.scalar.ComplexNumber) Test(org.junit.jupiter.api.Test)

Example 42 with ComplexNumber

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);
}
Also used : ComplexNumber(org.ojalgo.scalar.ComplexNumber) Test(org.junit.jupiter.api.Test)

Example 43 with ComplexNumber

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);
}
Also used : ComplexNumber(org.ojalgo.scalar.ComplexNumber) Normal(org.ojalgo.random.Normal)

Example 44 with ComplexNumber

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);
        }
    }
}
Also used : Quaternion(org.ojalgo.scalar.Quaternion) ComplexNumber(org.ojalgo.scalar.ComplexNumber)

Example 45 with ComplexNumber

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();
        }
    }
}
Also used : ComplexNumber(org.ojalgo.scalar.ComplexNumber)

Aggregations

ComplexNumber (org.ojalgo.scalar.ComplexNumber)53 Test (org.junit.jupiter.api.Test)20 NumberContext (org.ojalgo.type.context.NumberContext)16 DivideAndConquer (org.ojalgo.concurrent.DivideAndConquer)7 ComplexArray (org.ojalgo.array.ComplexArray)5 BigDecimal (java.math.BigDecimal)4 PrimitiveDenseStore (org.ojalgo.matrix.store.PrimitiveDenseStore)4 BasicMatrix (org.ojalgo.matrix.BasicMatrix)3 Householder (org.ojalgo.matrix.transformation.Householder)3 Tag (org.junit.jupiter.api.Tag)2 RationalMatrix (org.ojalgo.matrix.RationalMatrix)2 Solver (org.ojalgo.matrix.decomposition.MatrixDecomposition.Solver)2 ComplexDenseStore (org.ojalgo.matrix.store.ComplexDenseStore)2 Normal (org.ojalgo.random.Normal)2 Quaternion (org.ojalgo.scalar.Quaternion)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Uniform (org.ojalgo.random.Uniform)1