public class ComplexArrayMath
extends java.lang.Object
Modifier | Constructor and Description |
---|---|
protected |
ComplexArrayMath() |
Modifier and Type | Method and Description |
---|---|
protected static int |
_commonLength(Complex[] array1,
Complex[] array2,
java.lang.String methodName)
Throw an exception if the two arrays are not of the same length,
or if either array is null.
|
static Complex[] |
add(Complex[] array,
Complex z)
Return a new array that is constructed from array by
adding the complex number z to every element of array.
|
static Complex[] |
add(Complex[] array1,
Complex[] array2)
Return a new array that is the element-by-element sum of the two
input arrays.
|
static Complex[] |
append(Complex[] array1,
Complex[] array2)
Return a new array that is the result of appending array2
to the end of array1.
|
static Complex[] |
append(Complex[] array1,
int idx1,
int length1,
Complex[] array2,
int idx2,
int length2)
Return a new array that is the result of appending
length2 elements of array2, starting from the
idx2th element, to length1 elements of
array1, starting from the idx1th element.
|
static Complex[] |
applyBinaryOperation(ComplexBinaryOperation op,
Complex[] array,
Complex z)
Return a new array that is formed by applying an instance of a
ComplexBinaryOperation to each element in the input array,
using z as the right operand in all cases and the array elements
as the left operands (op.operate(array[i], z)).
|
static Complex[] |
applyBinaryOperation(ComplexBinaryOperation op,
Complex[] array1,
Complex[] array2)
Return a new array that is formed by applying an instance of a
ComplexBinaryOperation to the two arrays, element by element,
using the elements of the first array as the left operands and the
elements of the second array as the right operands.
|
static Complex[] |
applyBinaryOperation(ComplexBinaryOperation op,
Complex z,
Complex[] array)
Return a new array that is formed by applying an instance of a
ComplexBinaryOperation to each element in the input array,
using z as the left argument to op in all cases and
the array elements as the right arguments (op.operate(z, array[i])).
|
static Complex[] |
applyUnaryOperation(ComplexUnaryOperation op,
Complex[] array)
Return a new array that is formed by applying an instance of a
ComplexUnaryOperation to each element in the input array
(op.operate(array[i])).
|
static Complex[] |
conjugate(Complex[] array)
Return a new array of complex numbers that is formed by taking the
complex-conjugate of each element in the argument array.
|
static Complex[] |
divide(Complex[] array,
Complex divisor)
Return a new array that is the result of dividing each element of
the given array by the given value.
|
static Complex[] |
divideElements(Complex[] array1,
Complex[] array2)
Return a new array that is the element-by-element division of
the first array by the second array.
|
static Complex |
dotProduct(Complex[] array1,
Complex[] array2)
Return a complex number that is the dot product of the two argument
arrays.
|
static Complex[] |
formComplexArray(double[] realPart,
double[] imagPart)
Return a new array of Complex numbers using two arrays for the
real and imaginary parts.
|
static double[] |
imagParts(Complex[] x)
Return a new array of doubles with the imaginary parts of the array of
complex numbers.
|
static double |
l2norm(Complex[] array)
Return a double that is the L2-norm of the array.
|
static double |
l2normSquared(Complex[] array)
Return a double that is the sum of the squared magnitudes of
the elements of array.
|
static Complex[] |
limit(Complex[] array,
Complex bottom,
Complex top)
Return a new array that is a copy of the first argument except
that the elements are limited to lie within the specified range.
|
static double[] |
magnitude(Complex[] array)
Return a new array of doubles containing the magnitudes of the elements
of the specified array of complex numbers.
|
static Complex[] |
multiply(Complex[] array,
Complex factor)
Return a new array that is constructed from the argument by
multiplying each element in array by the second argument,
which is a complex number.
|
static Complex[] |
multiply(Complex[] array1,
Complex[] array2)
Return a new array that is the element-by-element multiplication of
the two input arrays.
|
static Complex[] |
negative(Complex[] array)
Return a new array that is the formed from the additive inverse of each
element of the input array (-array[i]).
|
static Complex[] |
padMiddle(Complex[] array,
int newLength)
Return a new array of Complex numbers that is formed by padding the
middle of the array with 0's.
|
static double[] |
phase(Complex[] array)
Return a new array containing the angles of the elements of the
specified complex array.
|
static Complex[] |
polynomial(Complex[] roots)
Given the roots of a polynomial, return a polynomial that has
has such roots.
|
static Complex[] |
pow(Complex[] array,
double exponent)
Return a new array of complex numbers that is formed by raising each
element to the specified exponent, a double.
|
static Complex |
product(Complex[] array)
Return the product of the elements in the array.
|
static double[] |
realParts(Complex[] x)
Return a new array of doubles that includes the real
parts of the array of complex numbers.
|
static Complex[] |
resize(Complex[] array,
int newLength)
Return a new array of length newLength that is formed by
either truncating or padding the input array.
|
static Complex[] |
resize(Complex[] array,
int newLength,
int startIdx)
Return a new array of length newLength that is formed by
either truncating or padding the input array.
|
static Complex[] |
scale(Complex[] array,
Complex factor)
Return a new array that is constructed from the argument by
scaling each element in array by factor, which is a
complex number.
|
static Complex[] |
scale(Complex[] array,
double factor)
Return a new array that is constructed from the argument by
scaling each element in the array by factor, which is a
double.
|
static Complex[] |
subtract(Complex[] array,
Complex z)
Return a new array that is constructed by subtracting the complex
number z from every element in the given array.
|
static Complex[] |
subtract(Complex[] array1,
Complex[] array2)
Return a new array that is the element-by-element
subtraction of the second array from the first array.
|
static java.lang.String |
toString(Complex[] array)
Return a new String representing the array, formatted as
in Java array initializers.
|
static java.lang.String |
toString(Complex[] array,
java.lang.String elementDelimiter,
java.lang.String vectorBegin,
java.lang.String vectorEnd)
Return a new String representing the array, formatted
specified starting with vectorBegin, where each
successive element is separated by elementDelimiter
and ending with vectorEnd.
|
static boolean |
within(Complex[] array1,
Complex[] array2,
Complex maxError)
Return true if all the distances between corresponding elements
array1 and array2 are all less than or equal to
the magnitude of maxError.
|
static boolean |
within(Complex[] array1,
Complex[] array2,
Complex[] maxError)
Return true if all the distances between corresponding elements
array1 and array2 are all less than or equal to
the magnitudes of the corresponding elements in maxError.
|
static boolean |
within(Complex[] array1,
Complex[] array2,
double maxError)
Return true if all the distances between corresponding elements
array1 and array2 are all less than or equal to
maxError.
|
static boolean |
within(Complex[] array1,
Complex[] array2,
double[] maxError)
Return true if all the distances between corresponding elements
array1 and array2 are all less than or equal to
the corresponding elements in maxError.
|
public static final Complex[] add(Complex[] array, Complex z)
array
- An array of complex numbers.z
- The complex number to be added to each element of array.public static final Complex[] add(Complex[] array1, Complex[] array2)
array1
- The first array.array2
- The second array.java.lang.IllegalArgumentException
- If the arrays are not of the same
length.public static final Complex[] append(Complex[] array1, Complex[] array2)
array1
- The first array of complex numbers.array2
- The second array of complex numbers.public static final Complex[] append(Complex[] array1, int idx1, int length1, Complex[] array2, int idx2, int length2)
array1
- The first array of complex numbers.idx1
- The starting index for array1.length1
- The number of elements of array1 to use.array2
- The second array of complex numbers, which is appended.idx2
- The starting index for array2.length2
- The number of elements of array2 to append.public static final Complex[] applyBinaryOperation(ComplexBinaryOperation op, Complex z, Complex[] array)
op
- The complex binary operation to be applied to the given
complex number and complex array.z
- The complex number that is the first argument to op.array
- The array of complex numbers that is the second argument
to op.public static final Complex[] applyBinaryOperation(ComplexBinaryOperation op, Complex[] array, Complex z)
op
- The complex binary operation to be applied to the given
complex number and complex array.z
- The complex number that is the second argument to op.array
- The array of complex numbers that is the first argument
to op.public static final Complex[] applyBinaryOperation(ComplexBinaryOperation op, Complex[] array1, Complex[] array2)
op
- The complex binary operation to be applied to each pair
of corresponding elements of each complex array.array1
- The first array.array2
- The second array.java.lang.IllegalArgumentException
- If the arrays are not of the same
length.public static final Complex[] applyUnaryOperation(ComplexUnaryOperation op, Complex[] array)
op
- The complex unary operation to be applied to each
element of the given complex array.array
- An array of complex numbers.public static final Complex[] conjugate(Complex[] array)
array
- The given array of complex numbers.public static final Complex[] divideElements(Complex[] array1, Complex[] array2)
array1
- The first array of complex numbers.array2
- The second array of complex numbers.java.lang.IllegalArgumentException
- If the arrays are not of the same
length.public static final Complex[] divide(Complex[] array, Complex divisor)
array
- An array of complex numbers.divisor
- The number by which to divide each element of the array.public static final Complex dotProduct(Complex[] array1, Complex[] array2)
array1
- The first array of complex numbers.array2
- The second array of complex numbers.java.lang.IllegalArgumentException
- If the arrays are not of the same
length.public static final Complex[] formComplexArray(double[] realPart, double[] imagPart)
realPart
- An array of doubles, used for the real parts.imagPart
- An array of doubles, used for the imaginary parts.public static final double[] imagParts(Complex[] x)
x
- The input array of complex numbers.public static final double l2norm(Complex[] array)
array
- The given array of complex numbers.public static final double l2normSquared(Complex[] array)
array
- The given array of complex numbers.public static final Complex[] limit(Complex[] array, Complex bottom, Complex top) throws java.lang.IllegalArgumentException
array
- An array of complex numbers.bottom
- The bottom limit.top
- The top limit.java.lang.IllegalArgumentException
- If bottom has either a
real or imaginary part larger than the corresponding part of
top.public static final double[] magnitude(Complex[] array)
array
- The given array of complex numbers.public static final Complex[] multiply(Complex[] array1, Complex[] array2)
array1
- The first array of complex numbers.array2
- The second array of complex numbers.java.lang.IllegalArgumentException
- If the arrays are not of the same
length.public static final Complex[] multiply(Complex[] array, Complex factor)
array
- An array of complex numbers.factor
- The complex number by which each element of array
is multiplied by.public static final Complex[] negative(Complex[] array)
array
- The given array of complex numbers.public static final Complex[] padMiddle(Complex[] array, int newLength)
array
- An array of complex numbers.newLength
- The desired length of the returned array.public static final double[] phase(Complex[] array)
array
- An array of complex numbers.public static final Complex[] polynomial(Complex[] roots)
a0 + a1z-1 + ... + aNz-N = (1 - r0z-1) (1 - r1z-1) ... (1 - rN-1z-1). The returned polynomial will always be monic, meaning that a0 = 1.
roots
- An array of roots of a polynomial.public static final Complex[] pow(Complex[] array, double exponent)
array
- The input array of complex numbers.exponent
- A double, which is the exponent.public static final Complex product(Complex[] array)
array
- An array of complex numbers.public static final double[] realParts(Complex[] x)
x
- An array of complex numberspublic static final Complex[] resize(Complex[] array, int newLength)
array
- An array of complex numbers.newLength
- The desired size of the output array.public static final Complex[] resize(Complex[] array, int newLength, int startIdx)
array
- An array of complex numbers.newLength
- The desired size of the output array.startIdx
- The starting index for the input array.public static final Complex[] scale(Complex[] array, Complex factor)
array
- An array of complex numbers.factor
- A complex number used to multiply each element
of array by.public static final Complex[] scale(Complex[] array, double factor)
array
- An array of complex numbers.factor
- A double used to multiply each element
of array by.public static final Complex[] subtract(Complex[] array, Complex z)
array
- An array of complex numbers.z
- A complex number subtracted from each element of array.public static final Complex[] subtract(Complex[] array1, Complex[] array2)
array1
- An array of complex numbers from which to subtract.array2
- An array of complex numbers to subtract.java.lang.IllegalArgumentException
- If the arrays are not of the same
length.public static final java.lang.String toString(Complex[] array)
array
- An array of complex numbers.public static final java.lang.String toString(Complex[] array, java.lang.String elementDelimiter, java.lang.String vectorBegin, java.lang.String vectorEnd)
array
- An array of complex numbers.elementDelimiter
- The delimiter between elements,
typically ", ".vectorBegin
- The start of the array, typically "{".vectorEnd
- The end of the array, typically "}".public static final boolean within(Complex[] array1, Complex[] array2, Complex maxError)
array1
- The first array.array2
- The second array.maxError
- A complex number whose magnitude is taken to
be the distance threshold.java.lang.IllegalArgumentException
- If the arrays are not of the same
length.public static final boolean within(Complex[] array1, Complex[] array2, double maxError)
array1
- The first array.array2
- The second array.maxError
- The threshold for the magnitude of the difference.java.lang.IllegalArgumentException
- If the arrays are not of the same
length.public static final boolean within(Complex[] array1, Complex[] array2, double[] maxError)
array1
- The first array.array2
- The second array.maxError
- The array of thresholds for the magnitudes of
the difference.java.lang.IllegalArgumentException
- If the arrays are not of the same
length.public static final boolean within(Complex[] array1, Complex[] array2, Complex[] maxError)
Note that there is no notion of negative distance with complex numbers, so unlike the within() methods for other types, this method will not return false if an element of the maxError matrix is negative.
array1
- The first array.array2
- The second array.maxError
- An array of complex numbers whose magnitude
for each element is taken to be the distance threshold.java.lang.IllegalArgumentException
- If the arrays are not of the same
length.protected static final int _commonLength(Complex[] array1, Complex[] array2, java.lang.String methodName)
array1
- The first array of doubles.array2
- The second array of doubles.methodName
- A String representing the method name of the caller,
without parentheses.