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;
}
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);
}
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();
}
}
}
Aggregations