Class ComplexNumber
java.lang.Object
org.ojalgo.scalar.ComplexNumber
- All Implemented Interfaces:
Comparable<ComplexNumber>, Field<Scalar<ComplexNumber>>, Group, Group.Additive<Scalar<ComplexNumber>>, Group.Multiplicative<Scalar<ComplexNumber>>, NormedVectorSpace<Scalar<ComplexNumber>, ComplexNumber>, Operation, Operation.Addition<Scalar<ComplexNumber>>, Operation.Division<Scalar<ComplexNumber>>, Operation.Multiplication<Scalar<ComplexNumber>>, Operation.Subtraction<Scalar<ComplexNumber>>, Ring<Scalar<ComplexNumber>>, ScalarOperation, ScalarOperation.Addition<Scalar<ComplexNumber>, ComplexNumber>, ScalarOperation.Division<Scalar<ComplexNumber>, ComplexNumber>, ScalarOperation.Multiplication<Scalar<ComplexNumber>, ComplexNumber>, ScalarOperation.Subtraction<Scalar<ComplexNumber>, ComplexNumber>, VectorSpace<Scalar<ComplexNumber>, ComplexNumber>, Scalar<ComplexNumber>, SelfDeclaringScalar<ComplexNumber>, Access1D<Double>, Access2D<Double>, Access2D.Collectable<Double,Mutate2D>, AccessScalar<ComplexNumber>, Structure1D, Structure2D, Transformation2D<Double>, Tensor<ComplexNumber, Scalar<ComplexNumber>>, NumberContext.Enforceable<ComplexNumber>, NumberDefinition
public final class ComplexNumber
extends Object
implements SelfDeclaringScalar<ComplexNumber>, Access2D<Double>, Transformation2D<Double>, Access2D.Collectable<Double,Mutate2D>
ComplexNumber is an immutable complex number class. It only implements the most basic complex number
operations. ComplexFunction implements some of the more complicated ones.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface Access2D
Access2D.Aggregatable<N>, Access2D.Collectable<N,R>, Access2D.ColumnView<N>, Access2D.ElementView<N>, Access2D.RowView<N>, Access2D.SelectionView<N>, Access2D.Sliceable<N>, Access2D.Visitable<N> Nested classes/interfaces inherited from interface Group
Group.Additive<T>, Group.Multiplicative<T>Nested classes/interfaces inherited from interface Operation
Operation.Addition<T>, Operation.Division<T>, Operation.Multiplication<T>, Operation.Subtraction<T>Nested classes/interfaces inherited from interface Scalar
Scalar.Factory<N>Nested classes/interfaces inherited from interface ScalarOperation
ScalarOperation.Addition<T,N>, ScalarOperation.Division<T, N>, ScalarOperation.Multiplication<T, N>, ScalarOperation.Subtraction<T, N> Nested classes/interfaces inherited from interface Structure1D
Structure1D.BasicMapper<T>, Structure1D.IndexMapper<T>, Structure1D.IntIndex, Structure1D.Logical<S,B>, Structure1D.LongIndex, Structure1D.LoopCallback Nested classes/interfaces inherited from interface Structure2D
Structure2D.IntRowColumn, Structure2D.Logical<S,B>, Structure2D.LongRowColumn, Structure2D.ReducibleTo1D<R>, Structure2D.Reshapable, Structure2D.RowColumnKey<R, C>, Structure2D.RowColumnMapper<R, C> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final doublestatic final Scalar.Factory<ComplexNumber> final doublestatic final ComplexNumberComplex numberi, Z = (0.0 + 1.0i), satisfies i2 = -1;static final ComplexNumberComplex number Z = (+∞ + 0.0i)private static final Stringprivate static final Stringprivate final booleanprivate final doublestatic final ComplexNumberComplex number-i, Z = (0.0 - 1.0i)static final ComplexNumberComplex number Z = (NaN + NaNi)static final ComplexNumberComplex number Z = (-1.0 + 0.0i)static final ComplexNumberComplex number Z = (1.0 + 0.0i)private static final Stringprivate static final Stringstatic final ComplexNumberComplex number Z = (2.0 + 0.0i)static final ComplexNumberComplex number Z = (0.0 + 0.0i) -
Constructor Summary
ConstructorsModifierConstructorDescriptionComplex number constructor, returnsZEROprivateComplexNumber(double real) (package private)ComplexNumber(double real, double imaginary) -
Method Summary
Modifier and TypeMethodDescriptionadd(double arg) Performs the binary operation '+' with a real numberadd(ComplexNumber arg) Performs the binary operation '+' with a complex number.intcompareTo(ComplexNumber other) First compares the real values.Returns the conjugate of this complex number.longcount()count() == countRows() * countColumns()longOnly need to implement if the structure may contain more than Integer.MAX_VALUE elements.longOnly need to implement if the structure may contain more than Integer.MAX_VALUE elements.divide(double arg) Performs the binary operation '/' with a real number.divide(ComplexNumber arg) Performs the binary operation '/' with a complex number.doubledoubledoubleValue(int index) doubledoubleValue(int row, int col) Extracts one element of this matrix as a double.enforce(NumberContext context) Will call NumberContext.enforce(double) on the real and imaginary parts separately.booleanfloatget()get(long index) get(long row, long col) doubleintdoubledoubledoublegetReal()intinthashCode()intintValue()invert()Performs the unary operation '1/x'booleanstatic booleanisAbsolute(ComplexNumber value) static booleanisInfinite(ComplexNumber value) Test ifvalueis infinite.static booleanisNaN(ComplexNumber value) Test ifvalueis NaN.booleanisReal()static booleanisReal(ComplexNumber value) Test ifvalueis real.booleanisSmall(double comparedTo) static booleanisSmall(double comparedTo, ComplexNumber value) booleanisZero()Tests if this scalar value is exactly zero.longstatic ComplexNumbermakePolar(double norm, double phase) Static factory method returning a complex number from polar coordinatesstatic ComplexNumbermakeRotation(double angle) multiply(double arg) Performs the binary operation '*' with a real number.multiply(ComplexNumber arg) Performs the binary operation '*' with a complex number.doublemultiplyIm(double argRe, double argIm) The imaginary part of the complex number resulting when multiplying this with a complex number whose real and imaginary parts are argRe and argIm.doublemultiplyRe(double argRe, double argIm) The real part of the complex number resulting when multiplying this with a complex number whose real and imaginary parts are argRe and argIm.negate()Performs the unary operation '-'.static ComplexNumbernewUnitRoot(int nbRoots) static ComplexNumber[]newUnitRoots(int nbRoots) doublenorm()Returns the norm of this complex number.static ComplexNumberof(double real, double imaginary) Static factory method returning a complex number from cartesian coordinates.doublephase()Returns the phase of this complex number.power(int power) Multiply by itselfpowertimes.signum()this == this.signum().multiply(this.norm())subtract(double arg) Performs the binary operation '-' with a real number.subtract(ComplexNumber arg) Performs the binary operation '-' with a complex number.voidtoString()toString(NumberContext context) <T extends Mutate2D.ModifiableReceiver<Double>>
voidtransform(T transformable) (package private) <T extends Mutate2D.ModifiableReceiver<Double>>
voidtransformWhenUnit(T transformable) static ComplexNumbervalueOf(double value) Static factory method returning a complex number from a real valuestatic ComplexNumbervalueOf(Comparable<?> number) Static factory method returning a complex number from arbitrary numberMethods inherited from interface Access1D
asCollectable1D, asKeyed1D, asList, axpy, dot, select, supplyTo, toList, toRawCopy1DMethods inherited from interface Access2D
asCollectable2D, asKeyed2D, byteValue, byteValue, byteValue, byteValue, columns, columns, columns, doubleValue, doubleValue, elements, floatValue, floatValue, floatValue, floatValue, intValue, intValue, intValue, intValue, longValue, longValue, longValue, longValue, nonzeros, rows, rows, rows, select, select, shortValue, shortValue, shortValue, shortValue, toRawCopy2DMethods inherited from interface Access2D.Collectable
collectMethods inherited from interface NumberDefinition
booleanValue, byteValue, shortValueMethods inherited from interface Scalar
add, dimensions, divide, multiply, rank, subtract, toPlainStringMethods inherited from interface SelfDeclaringScalar
add, divide, multiply, subtractMethods inherited from interface Structure2D
firstInColumn, firstInRow, getMaxDim, getMinDim, isEmpty, isFat, isScalar, isSquare, isTall, isVector, limitOfColumn, limitOfRow, sizeMethods inherited from interface Tensor
components, isSameShape
-
Field Details
-
FACTORY
-
I
Complex numberi, Z = (0.0 + 1.0i), satisfies i2 = -1; -
INFINITY
Complex number Z = (+∞ + 0.0i) -
N
Complex number-i, Z = (0.0 - 1.0i) -
NaN
Complex number Z = (NaN + NaNi) -
NEG
Complex number Z = (-1.0 + 0.0i) -
ONE
Complex number Z = (1.0 + 0.0i) -
TWO
Complex number Z = (2.0 + 0.0i) -
ZERO
Complex number Z = (0.0 + 0.0i) -
ARGUMENT_TOLERANCE
private static final double ARGUMENT_TOLERANCE -
LEFT
- See Also:
-
MINUS
- See Also:
-
PLUS
- See Also:
-
RIGHT
- See Also:
-
i
public final double i -
myRealForSure
private final boolean myRealForSure -
myRealValue
private final double myRealValue
-
-
Constructor Details
-
ComplexNumber
public ComplexNumber()Complex number constructor, returnsZERO -
ComplexNumber
private ComplexNumber(double real) -
ComplexNumber
ComplexNumber(double real, double imaginary)
-
-
Method Details
-
isAbsolute
-
isInfinite
Test ifvalueis infinite. A complex number is infinite if its real part and/or its imaginary part is infinite.- Parameters:
value- the complex number to test- Returns:
- true if the specified value is infinite (real and/or imaginary part) otherwise false
-
isNaN
Test ifvalueis NaN. A complex number is NaN if its real and/or its imaginary part is NaN.- Parameters:
value- the complex number to test- Returns:
- true if the specified value is NaN (real and/or imaginary part) otherwise false
-
isReal
Test ifvalueis real. A complex number Z is real if and only if Im(Z) = 0.0.- Parameters:
value- the complex number to test- Returns:
- true if the imaginary part of the specified value is null otherwise false
-
isSmall
-
makePolar
Static factory method returning a complex number from polar coordinates- Parameters:
norm- the complex number's normphase- the complex number's phase- Returns:
- a complex number
-
makeRotation
-
newUnitRoot
-
newUnitRoots
-
of
Static factory method returning a complex number from cartesian coordinates.- Parameters:
real- the complex number's real partimaginary- the complex number's imaginary part- Returns:
- a complex number
-
valueOf
Static factory method returning a complex number from arbitrary number- Parameters:
number- a numeric value- Returns:
ZEROifnumberis null otherwise the double value ofnumber
-
valueOf
Static factory method returning a complex number from a real value- Parameters:
value- the complex number's real part- Returns:
- a complex number Z = (
value+ 0.0i)
-
add
Performs the binary operation '+' with a complex number.- Specified by:
addin interfaceScalarOperation.Addition<Scalar<ComplexNumber>, ComplexNumber>- Specified by:
addin interfaceSelfDeclaringScalar<ComplexNumber>- Parameters:
arg- the complex number to add- Returns:
- a complex number Z = ((Re(this) + Re(arg)) + (Im(this) + Im(arg))i)
-
add
Performs the binary operation '+' with a real number- Specified by:
addin interfaceScalarOperation.Addition<Scalar<ComplexNumber>, ComplexNumber>- Specified by:
addin interfaceSelfDeclaringScalar<ComplexNumber>- Parameters:
arg- the real number to add- Returns:
- a complex number Z = ((Re(this) + arg) + Im(this)i)
-
compareTo
First compares the real values. Only if they are equal will compare the imaginary part.- Specified by:
compareToin interfaceComparable<ComplexNumber>
-
conjugate
Returns the conjugate of this complex number. A complex number conjugate is its reflexion about the real axis.- Specified by:
conjugatein interfaceSelfDeclaringScalar<ComplexNumber>- Specified by:
conjugatein interfaceVectorSpace<Scalar<ComplexNumber>, ComplexNumber>- Returns:
- a complex number Z = (Re(this) - Im(this)i)
-
count
public long count()Description copied from interface:Structure2Dcount() == countRows() * countColumns()- Specified by:
countin interfaceStructure1D- Specified by:
countin interfaceStructure2D
-
countColumns
public long countColumns()Description copied from interface:Structure2DOnly need to implement if the structure may contain more than Integer.MAX_VALUE elements.- Specified by:
countColumnsin interfaceStructure2D- Returns:
- The number of columns
-
countRows
public long countRows()Description copied from interface:Structure2DOnly need to implement if the structure may contain more than Integer.MAX_VALUE elements.- Specified by:
countRowsin interfaceStructure2D- Returns:
- The number of rows
-
divide
Performs the binary operation '/' with a complex number.- Specified by:
dividein interfaceScalarOperation.Division<Scalar<ComplexNumber>, ComplexNumber>- Specified by:
dividein interfaceSelfDeclaringScalar<ComplexNumber>- Parameters:
arg- the complex number to divide by- Returns:
- a complex number Z = this / arg
-
divide
Performs the binary operation '/' with a real number.- Specified by:
dividein interfaceScalarOperation.Division<Scalar<ComplexNumber>, ComplexNumber>- Specified by:
dividein interfaceSelfDeclaringScalar<ComplexNumber>- Parameters:
arg- the real number to divide by- Returns:
- a complex number Z = ((Re(this) / arg) + (Im(this) / arg)i)
-
doubleValue
public double doubleValue()- Specified by:
doubleValuein interfaceNumberDefinition
-
doubleValue
public double doubleValue(int index) - Specified by:
doubleValuein interfaceAccess1D<Double>- Specified by:
doubleValuein interfaceAccess2D<Double>
-
doubleValue
public double doubleValue(int row, int col) Description copied from interface:Access2DExtracts one element of this matrix as a double.- Specified by:
doubleValuein interfaceAccess2D<Double>- Parameters:
row- A row index.col- A column index.- Returns:
- One matrix element
-
enforce
Will call NumberContext.enforce(double) on the real and imaginary parts separately.- Specified by:
enforcein interfaceNumberContext.Enforceable<ComplexNumber>
-
equals
-
floatValue
public float floatValue()- Specified by:
floatValuein interfaceNumberDefinition
-
get
- Specified by:
getin interfaceAccessScalar<ComplexNumber>
-
get
-
get
-
getArgument
public double getArgument() -
getColDim
public int getColDim()- Specified by:
getColDimin interfaceStructure2D- Returns:
- The number of columns
-
getImaginary
public double getImaginary() -
getModulus
public double getModulus() -
getReal
public double getReal() -
getRowDim
public int getRowDim()- Specified by:
getRowDimin interfaceStructure2D- Returns:
- The number of rows
-
hashCode
-
intValue
public int intValue()- Specified by:
intValuein interfaceNumberDefinition
-
invert
Performs the unary operation '1/x'- Specified by:
invertin interfaceGroup.Multiplicative<Scalar<ComplexNumber>>- Specified by:
invertin interfaceSelfDeclaringScalar<ComplexNumber>- Returns:
- the complex number Z inverse of this, satisfies Z * this = 1
-
isAbsolute
public boolean isAbsolute()- Specified by:
isAbsolutein interfaceScalar<ComplexNumber>- Returns:
- true if this is equal to its own norm, modulus or absolute value (non-negative real part and no imaginary part); otherwise false.
- See Also:
-
isReal
public boolean isReal() -
isSmall
public boolean isSmall(double comparedTo) - Specified by:
isSmallin interfaceNormedVectorSpace<Scalar<ComplexNumber>, ComplexNumber>- Parameters:
comparedTo- What to compare with- Returns:
- true if this is small compared to the magnitude of the input reference value.
-
isZero
public boolean isZero()Description copied from interface:ScalarTests if this scalar value is exactly zero.Each implementation should test for zero as exactly as possible based on what's achievable with that specific scalar type. The purpose is NOT to have similar behavior between different implementations, but rather to leverage the full precision and capabilities of each type.
For example:
- Primitive types (like
double) should use exact equality comparison - High-precision types (like
Quadruple) should check both base and remainder components - Arbitrary-precision types (like
BigDecimal) should use their built-in zero detection - Complex types should check both real and imaginary parts
This method should NOT use tolerance-based comparisons or approximate zero detection, as those are better handled by context-aware methods like
NormedVectorSpace.isSmall(double).- Specified by:
isZeroin interfaceScalar<ComplexNumber>- Returns:
- true if this scalar represents exactly zero, false otherwise
- See Also:
- Primitive types (like
-
longValue
public long longValue()- Specified by:
longValuein interfaceNumberDefinition
-
multiply
Performs the binary operation '*' with a complex number.- Specified by:
multiplyin interfaceScalarOperation.Multiplication<Scalar<ComplexNumber>, ComplexNumber>- Specified by:
multiplyin interfaceSelfDeclaringScalar<ComplexNumber>- Parameters:
arg- the complex number to multiply by- Returns:
- a complex number Z = this * arg
-
multiply
Performs the binary operation '*' with a real number.- Specified by:
multiplyin interfaceScalarOperation.Multiplication<Scalar<ComplexNumber>, ComplexNumber>- Specified by:
multiplyin interfaceSelfDeclaringScalar<ComplexNumber>- Parameters:
arg- the real number to multiply by- Returns:
- a complex number Z = ((Re(this) * arg) + Im(this) * arg))
-
multiplyIm
public double multiplyIm(double argRe, double argIm) The imaginary part of the complex number resulting when multiplying this with a complex number whose real and imaginary parts are argRe and argIm. -
multiplyRe
public double multiplyRe(double argRe, double argIm) The real part of the complex number resulting when multiplying this with a complex number whose real and imaginary parts are argRe and argIm. -
negate
Performs the unary operation '-'.- Specified by:
negatein interfaceGroup.Additive<Scalar<ComplexNumber>>- Specified by:
negatein interfaceSelfDeclaringScalar<ComplexNumber>- Returns:
- a complex number Z = -this
-
norm
public double norm()Returns the norm of this complex number. The norm of a complex number is defined by |Z| = (ZZ*)1/2.- Specified by:
normin interfaceNormedVectorSpace<Scalar<ComplexNumber>, ComplexNumber>- Returns:
- the norm of this complex number.
-
phase
public double phase()Returns the phase of this complex number. The phase of a complex number Z is the angle between the positive real axis and the straight line defined by origin and Z in complex plane.- Returns:
- the phase of this complex number
-
power
Description copied from interface:Operation.MultiplicationMultiply by itselfpowertimes.- Specified by:
powerin interfaceOperation.Multiplication<Scalar<ComplexNumber>>- Specified by:
powerin interfaceSelfDeclaringScalar<ComplexNumber>
-
signum
Description copied from interface:NormedVectorSpacethis == this.signum().multiply(this.norm())- Specified by:
signumin interfaceNormedVectorSpace<Scalar<ComplexNumber>, ComplexNumber>- Specified by:
signumin interfaceSelfDeclaringScalar<ComplexNumber>- Returns:
- A unit "vector"
-
subtract
Performs the binary operation '-' with a complex number.- Specified by:
subtractin interfaceScalarOperation.Subtraction<Scalar<ComplexNumber>, ComplexNumber>- Specified by:
subtractin interfaceSelfDeclaringScalar<ComplexNumber>- Parameters:
arg- the complex number to subtract- Returns:
- a complex number Z = this -
arg
-
subtract
Performs the binary operation '-' with a real number.- Specified by:
subtractin interfaceScalarOperation.Subtraction<Scalar<ComplexNumber>, ComplexNumber>- Specified by:
subtractin interfaceSelfDeclaringScalar<ComplexNumber>- Parameters:
arg- the real number to subtract- Returns:
- a complex number Z = ((Re(this) - arg) + Im(this)i)
-
supplyTo
- Specified by:
supplyToin interfaceAccess2D.Collectable<Double,Mutate2D>
-
toBigDecimal
- Specified by:
toBigDecimalin interfaceScalar<ComplexNumber>
-
toMultiplicationMatrix
-
toMultiplicationVector
-
toRotationMatrix
-
toString
-
toString
- Specified by:
toStringin interfaceScalar<ComplexNumber>
-
transform
- Specified by:
transformin interfaceTransformation2D<Double>
-
transformWhenUnit
-