Search in sources :

Example 51 with ComplexNumber

use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.

the class MatrixUtils method makeRandomComplexStore.

public static PhysicalStore<ComplexNumber> makeRandomComplexStore(final int aRowDim, final int aColDim) {
    final PhysicalStore<ComplexNumber> retVal = GenericDenseStore.COMPLEX.makeZero(aRowDim, aColDim);
    final Uniform tmpArgGen = new Uniform(PrimitiveMath.ZERO, PrimitiveMath.TWO_PI);
    for (int j = 0; j < aColDim; j++) {
        for (int i = 0; i < aRowDim; i++) {
            retVal.set(i, j, ComplexNumber.makePolar(PrimitiveMath.E, tmpArgGen.doubleValue()).add(PrimitiveMath.PI));
        }
    }
    return retVal;
}
Also used : Uniform(org.ojalgo.random.Uniform) ComplexNumber(org.ojalgo.scalar.ComplexNumber)

Example 52 with ComplexNumber

use of org.ojalgo.scalar.ComplexNumber in project ojAlgo by optimatika.

the class OldGeneralEvD method doGeneral.

@Override
protected boolean doGeneral(final Collectable<N, ? super PhysicalStore<N>> matrix, final boolean eigenvaluesOnly) {
    final int tmpDiagDim = (int) matrix.countRows();
    // final DecompositionStore<N> tmpMtrxA = this.copy(matrix.get());
    final DecompositionStore<N> tmpMtrxA = this.makeZero(tmpDiagDim, tmpDiagDim);
    matrix.supplyTo(tmpMtrxA);
    final DecompositionStore<N> tmpV = this.makeEye(tmpDiagDim, tmpDiagDim);
    final Array1D<ComplexNumber> tmpEigenvalues = tmpMtrxA.computeInPlaceSchur(tmpV, true);
    this.setV(tmpV);
    this.setEigenvalues(tmpEigenvalues);
    final PhysicalStore<N> tmpD = this.makeZero(tmpDiagDim, tmpDiagDim);
    ComplexNumber tmpValue;
    double tmpImaginary;
    for (int ij = 0; ij < tmpDiagDim; ij++) {
        tmpValue = tmpEigenvalues.get(ij);
        tmpD.set(ij, ij, tmpValue.doubleValue());
        tmpImaginary = tmpValue.i;
        if (tmpImaginary > PrimitiveMath.ZERO) {
            tmpD.set(ij, ij + 1, tmpImaginary);
        } else if (tmpImaginary < PrimitiveMath.ZERO) {
            tmpD.set(ij, ij - 1, tmpImaginary);
        }
    }
    this.setD(tmpD);
    return this.computed(true);
}
Also used : ComplexNumber(org.ojalgo.scalar.ComplexNumber)

Example 53 with ComplexNumber

use of org.ojalgo.scalar.ComplexNumber in project ojAlgo-finance 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