Package org.ojalgo.scalar
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 org.ojalgo.structure.Access2D
Access2D.Aggregatable<N extends Comparable<N>>, Access2D.Collectable<N extends Comparable<N>,
R extends Mutate2D>, Access2D.ColumnView<N extends Comparable<N>>, Access2D.ElementView<N extends Comparable<N>>, Access2D.RowView<N extends Comparable<N>>, Access2D.SelectionView<N extends Comparable<N>>, Access2D.Sliceable<N extends Comparable<N>>, Access2D.Visitable<N extends Comparable<N>> Nested classes/interfaces inherited from interface org.ojalgo.algebra.Group
Group.Additive<T>, Group.Multiplicative<T>
Nested classes/interfaces inherited from interface org.ojalgo.algebra.Operation
Operation.Addition<T>, Operation.Division<T>, Operation.Multiplication<T>, Operation.Subtraction<T>
Nested classes/interfaces inherited from interface org.ojalgo.scalar.Scalar
Scalar.Factory<N extends Comparable<N>>
Nested classes/interfaces inherited from interface org.ojalgo.algebra.ScalarOperation
ScalarOperation.Addition<T,
N extends Comparable<N>>, ScalarOperation.Division<T, N extends Comparable<N>>, ScalarOperation.Multiplication<T, N extends Comparable<N>>, ScalarOperation.Subtraction<T, N extends Comparable<N>> Nested classes/interfaces inherited from interface org.ojalgo.structure.Structure1D
Structure1D.BasicMapper<T>, Structure1D.IndexMapper<T>, Structure1D.IntIndex, Structure1D.Logical<S extends Structure1D,
B extends Structure1D.Logical<S, B>>, Structure1D.LongIndex, Structure1D.LoopCallback Nested classes/interfaces inherited from interface org.ojalgo.structure.Structure2D
Structure2D.IntRowColumn, Structure2D.Logical<S extends Structure2D,
B extends Structure2D.Logical<S, B>>, Structure2D.LongRowColumn, Structure2D.ReducibleTo1D<R extends Structure1D>, Structure2D.Reshapable, Structure2D.RowColumnKey<R, C>, Structure2D.RowColumnMapper<R, C> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final double
static final Scalar.Factory
<ComplexNumber> final double
static final ComplexNumber
Complex numberi
, Z = (0.0 + 1.0i), satisfies i2 = -1;static final ComplexNumber
Complex number Z = (+∞ + 0.0i)private static final String
private static final String
private final boolean
private final double
static final ComplexNumber
Complex number-i
, Z = (0.0 - 1.0i)static final ComplexNumber
Complex number Z = (NaN + NaNi)static final ComplexNumber
Complex number Z = (-1.0 + 0.0i)static final ComplexNumber
Complex number Z = (1.0 + 0.0i)private static final String
private static final String
static final ComplexNumber
Complex number Z = (2.0 + 0.0i)static final ComplexNumber
Complex number Z = (0.0 + 0.0i) -
Constructor Summary
ConstructorsModifierConstructorDescriptionComplex number constructor, returnsZERO
private
ComplexNumber
(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.int
compareTo
(ComplexNumber other) First compares the real values.Returns the conjugate of this complex number.long
count()
count() == countRows() * countColumns()long
Only need to implement if the structure may contain more than Integer.MAX_VALUE elements.long
Only 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.double
double
doubleValue
(int index) double
doubleValue
(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.boolean
float
get()
get
(long index) get
(long row, long col) double
int
double
double
double
getReal()
int
int
hashCode()
int
intValue()
invert()
Performs the unary operation '1/x'boolean
static boolean
isAbsolute
(ComplexNumber value) static boolean
isInfinite
(ComplexNumber value) Test ifvalue
is infinite.static boolean
isNaN
(ComplexNumber value) Test ifvalue
is NaN.boolean
isReal()
static boolean
isReal
(ComplexNumber value) Test ifvalue
is real.boolean
isSmall
(double comparedTo) static boolean
isSmall
(double comparedTo, ComplexNumber value) long
static ComplexNumber
makePolar
(double norm, double phase) Static factory method returning a complex number from polar coordinatesstatic ComplexNumber
makeRotation
(double angle) multiply
(double arg) Performs the binary operation '*' with a real number.multiply
(ComplexNumber arg) Performs the binary operation '*' with a complex number.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.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 '-'.static ComplexNumber
newUnitRoot
(int nbRoots) static ComplexNumber[]
newUnitRoots
(int nbRoots) double
norm()
Returns the norm of this complex number.static ComplexNumber
of
(double real, double imaginary) Static factory method returning a complex number from cartesian coordinates.double
phase()
Returns the phase of this complex number.power
(int power) Multiply by itselfpower
times.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.void
toString()
toString
(NumberContext context) <T extends Mutate2D.ModifiableReceiver<Double>>
voidtransform
(T transformable) (package private) <T extends Mutate2D.ModifiableReceiver<Double>>
voidtransformWhenUnit
(T transformable) static ComplexNumber
valueOf
(double value) Static factory method returning a complex number from a real valuestatic ComplexNumber
valueOf
(Comparable<?> number) Static factory method returning a complex number from arbitrary numberMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.ojalgo.structure.Access1D
asCollectable1D, asKeyed1D, axpy, dot, select, supplyTo, toRawCopy1D
Methods inherited from interface org.ojalgo.structure.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, toRawCopy2D
Methods inherited from interface org.ojalgo.structure.Access2D.Collectable
collect
Methods inherited from interface org.ojalgo.type.NumberDefinition
booleanValue, byteValue, shortValue
Methods inherited from interface org.ojalgo.scalar.Scalar
add, dimensions, divide, multiply, rank, subtract, toPlainString
Methods inherited from interface org.ojalgo.scalar.SelfDeclaringScalar
add, divide, multiply, subtract
Methods inherited from interface org.ojalgo.structure.Structure2D
firstInColumn, firstInRow, getMaxDim, getMinDim, isEmpty, isFat, isScalar, isSquare, isTall, isVector, limitOfColumn, limitOfRow, size
Methods inherited from interface org.ojalgo.tensor.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 ifvalue
is 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 ifvalue
is 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 ifvalue
is 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:
ZERO
ifnumber
is 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:
add
in interfaceScalarOperation.Addition<Scalar<ComplexNumber>,
ComplexNumber> - Specified by:
add
in 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:
add
in interfaceScalarOperation.Addition<Scalar<ComplexNumber>,
ComplexNumber> - Specified by:
add
in 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:
compareTo
in interfaceComparable<ComplexNumber>
-
conjugate
Returns the conjugate of this complex number. A complex number conjugate is its reflexion about the real axis.- Specified by:
conjugate
in interfaceSelfDeclaringScalar<ComplexNumber>
- Specified by:
conjugate
in interfaceVectorSpace<Scalar<ComplexNumber>,
ComplexNumber> - Returns:
- a complex number Z = (Re(this) - Im(this)i)
-
count
public long count()Description copied from interface:Structure2D
count() == countRows() * countColumns()- Specified by:
count
in interfaceStructure1D
- Specified by:
count
in interfaceStructure2D
-
countColumns
public long countColumns()Description copied from interface:Structure2D
Only need to implement if the structure may contain more than Integer.MAX_VALUE elements.- Specified by:
countColumns
in interfaceStructure2D
- Returns:
- The number of columns
-
countRows
public long countRows()Description copied from interface:Structure2D
Only need to implement if the structure may contain more than Integer.MAX_VALUE elements.- Specified by:
countRows
in interfaceStructure2D
- Returns:
- The number of rows
-
divide
Performs the binary operation '/' with a complex number.- Specified by:
divide
in interfaceScalarOperation.Division<Scalar<ComplexNumber>,
ComplexNumber> - Specified by:
divide
in 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:
divide
in interfaceScalarOperation.Division<Scalar<ComplexNumber>,
ComplexNumber> - Specified by:
divide
in 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:
doubleValue
in interfaceNumberDefinition
-
doubleValue
public double doubleValue(int index) - Specified by:
doubleValue
in interfaceAccess1D<Double>
- Specified by:
doubleValue
in interfaceAccess2D<Double>
-
doubleValue
public double doubleValue(int row, int col) Description copied from interface:Access2D
Extracts one element of this matrix as a double.- Specified by:
doubleValue
in 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:
enforce
in interfaceNumberContext.Enforceable<ComplexNumber>
-
equals
-
floatValue
public float floatValue()- Specified by:
floatValue
in interfaceNumberDefinition
-
get
- Specified by:
get
in interfaceAccessScalar<ComplexNumber>
-
get
-
get
-
getArgument
public double getArgument() -
getColDim
public int getColDim()- Specified by:
getColDim
in interfaceStructure2D
- Returns:
- The number of columns
-
getImaginary
public double getImaginary() -
getModulus
public double getModulus() -
getReal
public double getReal() -
getRowDim
public int getRowDim()- Specified by:
getRowDim
in interfaceStructure2D
- Returns:
- The number of rows
-
hashCode
public int hashCode() -
intValue
public int intValue()- Specified by:
intValue
in interfaceNumberDefinition
-
invert
Performs the unary operation '1/x'- Specified by:
invert
in interfaceGroup.Multiplicative<Scalar<ComplexNumber>>
- Specified by:
invert
in interfaceSelfDeclaringScalar<ComplexNumber>
- Returns:
- the complex number Z inverse of this, satisfies Z * this = 1
-
isAbsolute
public boolean isAbsolute()- Specified by:
isAbsolute
in 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:
isSmall
in 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.
-
longValue
public long longValue()- Specified by:
longValue
in interfaceNumberDefinition
-
multiply
Performs the binary operation '*' with a complex number.- Specified by:
multiply
in interfaceScalarOperation.Multiplication<Scalar<ComplexNumber>,
ComplexNumber> - Specified by:
multiply
in 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:
multiply
in interfaceScalarOperation.Multiplication<Scalar<ComplexNumber>,
ComplexNumber> - Specified by:
multiply
in 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:
negate
in interfaceGroup.Additive<Scalar<ComplexNumber>>
- Specified by:
negate
in 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:
norm
in 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.Multiplication
Multiply by itselfpower
times.- Specified by:
power
in interfaceOperation.Multiplication<Scalar<ComplexNumber>>
- Specified by:
power
in interfaceSelfDeclaringScalar<ComplexNumber>
-
signum
Description copied from interface:NormedVectorSpace
this == this.signum().multiply(this.norm())
- Specified by:
signum
in interfaceNormedVectorSpace<Scalar<ComplexNumber>,
ComplexNumber> - Specified by:
signum
in interfaceSelfDeclaringScalar<ComplexNumber>
- Returns:
- A unit "vector"
-
subtract
Performs the binary operation '-' with a complex number.- Specified by:
subtract
in interfaceScalarOperation.Subtraction<Scalar<ComplexNumber>,
ComplexNumber> - Specified by:
subtract
in 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:
subtract
in interfaceScalarOperation.Subtraction<Scalar<ComplexNumber>,
ComplexNumber> - Specified by:
subtract
in interfaceSelfDeclaringScalar<ComplexNumber>
- Parameters:
arg
- the real number to subtract- Returns:
- a complex number Z = ((Re(this) - arg) + Im(this)i)
-
supplyTo
- Specified by:
supplyTo
in interfaceAccess2D.Collectable<Double,
Mutate2D>
-
toBigDecimal
- Specified by:
toBigDecimal
in interfaceScalar<ComplexNumber>
-
toMultiplicationMatrix
-
toMultiplicationVector
-
toRotationMatrix
-
toString
-
toString
- Specified by:
toString
in interfaceScalar<ComplexNumber>
-
transform
- Specified by:
transform
in interfaceTransformation2D<Double>
-
transformWhenUnit
-