|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.math.Complex
public class Complex
This class provides a complex data type and a library of functions that operate on and return complex numbers. An instance of the class is immutable, meaning that its value is set in the constructor and cannot then be modified. This is similar to the Java built-in classes like Double, Integer, etc.
Although this code is written from scratch, I looked at several designs and borrowed elements from each of them:
Red (cxh) |
Yellow (eal) |
Field Summary | |
---|---|
static double |
EPSILON
A small number ( = 1.0e-9). |
static Complex |
I
A Complex number representing i. |
double |
imag
The imaginary part. |
static Complex |
NEGATIVE_INFINITY
A Complex number representing negative infinity, by which we mean that both the real and imaginary parts are equal to Double.NEGATIVE_INFINITY. |
static Complex |
ONE
A Complex number representing one. |
static Complex |
POSITIVE_INFINITY
A Complex number representing positive infinity, by which we mean that both the real and imaginary parts are equal to Double.POSITIVE_INFINITY. |
double |
real
The real part. |
static Complex |
ZERO
A Complex number representing zero. |
Constructor Summary | |
---|---|
Complex()
Deprecated. Use Complex.ZERO instead. |
|
Complex(double real)
Construct a Complex with a zero imaginary part. |
|
Complex(double real,
double imag)
Construct a Complex with the specified real and imaginary parts. |
Method Summary | |
---|---|
static double |
abs(Complex x)
Return the magnitude or absolute value of the specified complex number. |
Complex |
acos()
Return the principal arc cosine of this complex number. |
static Complex |
acos(Complex z)
Return the principal arc cosine of the specified complex number. |
Complex |
acosh()
Return the principal hyperbolic arc cosine of this complex number. |
static Complex |
acosh(Complex z)
Return the principal hyperbolic arc cosine of the given complex number. |
Complex |
add(Complex z)
Return the sum of this complex number and the argument z. |
double |
angle()
Return the angle or argument of this complex number. |
static double |
angle(Complex z)
Return the angle or argument of this complex number. |
Complex |
asin()
Return the principal arc sine of this complex number. |
static Complex |
asin(Complex z)
Return the principal arc sine of the given complex number. |
Complex |
asinh()
Return the principal hyperbolic arc sine of this complex number. |
static Complex |
asinh(Complex z)
Return the principal hyperbolic arc sine of the given complex number. |
Complex |
atan()
Return the principal arc tangent of this complex number. |
static Complex |
atan(Complex z)
Return the principal arc tangent of the given complex number. |
Complex |
atanh()
Return the principal hyperbolic arc tangent of this complex number. |
static Complex |
atanh(Complex z)
Return the principal hyperbolic arc tangent of the given complex number. |
Complex |
conjugate()
Return the complex conjugate of this complex number. |
static Complex |
conjugate(Complex z)
Return the complex conjugate of the specified complex number. |
static Complex |
conjugate(double z)
Return the complex conjugate of the specified real number, which is just the real number itself. |
Complex |
cos()
Return the cosine of this complex number. |
static Complex |
cos(Complex z)
Return the cosine of the given complex number. |
Complex |
cosh()
Return the hyperbolic cosine of this complex number. |
static Complex |
cosh(Complex z)
Return the hyperbolic cosine of the given complex number. |
Complex |
cot()
Return the cotangent of this complex number. |
static Complex |
cot(Complex z)
Return the cotangent of the given complex number. |
Complex |
csc()
Return the cosecant of this complex number. |
static Complex |
csc(Complex z)
Return the cosecant of the given complex number. |
Complex |
divide(Complex divisor)
Divide this complex number by the argument, and return the result in a new Complex object. |
boolean |
equals(java.lang.Object z)
Return true if the real and imaginary parts of this complex number are equal to those of the argument. |
Complex |
exp()
Return the exponential of this complex number, or ez, where z is this complex number. |
static Complex |
exp(Complex z)
Return the exponential of the specified complex number, or ez, where z is the argument. |
int |
hashCode()
Return a hash code value for this Complex. |
static double |
imag(Complex z)
Return the imaginary part of the specified complex number. |
static double |
imag(double z)
Return the imaginary part of the specified real number, which is 0.0. |
boolean |
isCloseTo(Complex z)
Return true if the distance between this complex number and the argument is less than or equal to EPSILON. |
boolean |
isCloseTo(Complex z,
double distance)
Return true if the distance between this complex number and the first argument is less than or equal to the second argument. |
boolean |
isInfinite()
Return true if either the real or imaginary part is infinite. |
static boolean |
isInfinite(Complex z)
Return true if either the real or imaginary part of the given complex number is infinite. |
boolean |
isNaN()
Return true if either the real or imaginary part is NaN. |
static boolean |
isNaN(Complex z)
Return true if either the real or imaginary part of the given Complex number is NaN. |
Complex |
log()
Return the natural logarithm of this complex number. |
static Complex |
log(Complex z)
Return the natural logarithm of the specified complex number. |
double |
magnitude()
Return the magnitude or absolute value of this complex number. |
static double |
magnitude(Complex z)
Return the magnitude or absolute value of the given complex number. |
double |
magnitudeSquared()
Return the square of the magnitude of this complex number. |
static double |
magnitudeSquared(Complex z)
Return the square of the magnitude of this complex number. |
Complex |
multiply(Complex w)
Return a new complex number that is formed by multiplying this complex number by the specified complex number. |
Complex |
negate()
Negate this complex number. |
static Complex |
polarToComplex(double magnitude,
double angle)
Return a new complex number with the specified magnitude and angle. |
Complex |
pow(Complex y)
Return zy where z is this complex number and y is the argument, a Complex. |
static Complex |
pow(Complex z,
Complex y)
Return a new complex number with value z y where z is the first argument and y is the second argument. |
static Complex |
pow(Complex z,
double y)
Return a new complex number with value z y where z is the first argument and y is the second argument. |
Complex |
pow(double y)
Return a new complex number with value z y where z is this complex number and y is the argument, a double. |
static Complex |
pow(double z,
Complex y)
Return a new complex number with value z y where z is the first argument and y is the second argument. |
static double |
real(Complex z)
Return the real part of the specified complex number. |
static double |
real(double z)
Return the real part of the specified real number, which is the real number itself. |
Complex |
reciprocal()
Return the reciprocal of this complex number. |
static Complex |
reciprocal(Complex z)
Return the reciprocal of this complex number. |
static Complex[] |
roots(Complex z,
int n)
Return the nth roots of the given complex number in an array. |
Complex[] |
roots(int n)
Return the nth roots of this complex number in an array. |
Complex |
scale(double scalar)
Return a new complex number with value equal to the product of this complex number and the real argument. |
Complex |
sec()
Return a new complex number with value equal to the secant of this complex number. |
static Complex |
sec(Complex z)
Return a new complex number with value equal to the secant of the given complex number. |
Complex |
sin()
Return a new complex number with value equal to the sine of this complex number. |
static Complex |
sin(Complex z)
Return a new complex number with value equal to the sine of the given complex number. |
Complex |
sinh()
Return a new complex number with value equal to the hyperbolic sine of this complex number. |
static Complex |
sinh(Complex z)
Return a new complex number with value equal to the hyperbolic sine of this complex number. |
Complex |
sqrt()
Return a new complex number with its value equal to the the square root of this complex number. |
static Complex |
sqrt(Complex z)
Return a new complex number with its value equal to the the square root of the specified complex number. |
Complex |
subtract(Complex w)
Return a new complex number formed by subtracting the specified complex number from this complex number. |
Complex |
tan()
Return a new complex number with value equal to the tangent of this complex number. |
static Complex |
tan(Complex z)
Return a new complex number with value equal to the tangent of the given complex number. |
Complex |
tanh()
Return a new complex number with value equal to the hyperbolic tangent of this complex number. |
static Complex |
tanh(Complex z)
Return a new complex number with value equal to the hyperbolic tangent of the given complex number. |
java.lang.String |
toString()
Return a string representation of this Complex. |
static java.lang.String |
toString(Complex value)
Return a string representation of the given Complex. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public final double real
public final double imag
public static double EPSILON
public static final Complex NEGATIVE_INFINITY
public static final Complex POSITIVE_INFINITY
public static final Complex ZERO
public static final Complex ONE
public static final Complex I
Constructor Detail |
---|
public Complex()
public Complex(double real)
real
- The real part.public Complex(double real, double imag)
real
- The real part.imag
- The imaginary part.Method Detail |
---|
public static double abs(Complex x)
x
- The specified number.
public final Complex acos()
acos(z) = -i * log(z + i*sqrt(1 - z*z))where
z
is this complex number.
public static Complex acos(Complex z)
acos(z) = -i * log(z + i*sqrt(1 - z*z))where
z
is this complex number.
z
- A complex number.
public final Complex acosh()
acosh(z) = log(z + sqrt(z*z - 1))where
z
is this complex number.
public static Complex acosh(Complex z)
acosh(z) = log(z + sqrt(z*z - 1))where
z
is this complex number.
z
- A complex number.
public final Complex add(Complex z)
z
- A complex number.
public final double angle()
public static double angle(Complex z)
z
- A complex number.
public final Complex asin()
asin(z) = -i * log(i*z + sqrt(1 - z*z))where
z
is this complex number.
public static Complex asin(Complex z)
asin(z) = -i * log(i*z + sqrt(1 - z*z))where
z
is this complex number.
z
- A complex number.
public final Complex asinh()
asinh(z) = log(z + sqrt(z*z + 1))where
z
is this complex number.
public static Complex asinh(Complex z)
asinh(z) = log(z + sqrt(z*z + 1))where
z
is this complex number.
z
- A complex number.
public final Complex atan()
atan(z) = -i/2 * log((i-z)/(i+z))where
z
is this complex number.
public static Complex atan(Complex z)
atan(z) = -i/2 * log((i-z)/(i+z))where
z
is this complex number.
z
- A complex number.
public final Complex atanh()
atanh(z) = 1/2 * log((1+z)/(1-z))where
z
is this complex number.
public static Complex atanh(Complex z)
atanh(z) = 1/2 * log((1+z)/(1-z))where
z
is this complex number.
z
- A complex number.
public final Complex conjugate()
public static final Complex conjugate(Complex z)
z
- The specified complex number.
public static final Complex conjugate(double z)
z
- The specified real number.
public final Complex cos()
cos(z) = (exp(i*z) + exp(-i*z))/2where
z
is this complex number.
public static Complex cos(Complex z)
cos(z) = (exp(i*z) + exp(-i*z))/2where
z
is this complex number.
z
- A complex number.
public final Complex cosh()
cosh(z) = (exp(z) + exp(-z))/2where
z
is this complex number.
public static Complex cosh(Complex z)
cosh(z) = (exp(z) + exp(-z))/2where
z
is this complex number.
z
- A complex number.
public final Complex cot()
cot(z) = 1/tan(z)where
z
is this complex number.
public static Complex cot(Complex z)
cot(z) = 1/tan(z)where
z
is this complex number.
z
- A complex number.
public Complex csc()
csc(z) = 1/sin(z)where
z
is this complex number.
public static Complex csc(Complex z)
csc(z) = 1/sin(z)where
z
is this complex number.
z
- A complex number.
public final Complex divide(Complex divisor)
divisor
- The denominator in the division.
public final boolean equals(java.lang.Object z)
equals
in class java.lang.Object
z
- The argument to which this number is being compared.
public final Complex exp()
z
is this complex number.
public static Complex exp(Complex z)
z
is the argument.
z
- A complex exponent.
public int hashCode()
hashCode
in class java.lang.Object
public static double imag(Complex z)
z
- The complex number.
public static double imag(double z)
z
- The complex number.
public final boolean isCloseTo(Complex z)
z
- The number to compare against.
EPSILON
public final boolean isCloseTo(Complex z, double distance)
z
- The number to compare against.distance
- The distance criterion.
public final boolean isInfinite()
public static boolean isInfinite(Complex z)
z
- A complex number.
public final boolean isNaN()
public static boolean isNaN(Complex z)
z
- A complex number.
public final Complex log()
log(z) = log(abs(z)) + i * angle(z)where
z
is this complex number, abs(z)
is its magnitude, and angle(z)
is its angle.
public static Complex log(Complex z)
log(z) = log(abs(z)) + i * angle(z)where
z
is this complex number, abs(z)
is its magnitude, and angle(z)
is its angle.
z
- A complex number.
public final double magnitude()
public static double magnitude(Complex z)
z
- A complex number.
public double magnitudeSquared()
public static double magnitudeSquared(Complex z)
z
- A complex number.
public Complex multiply(Complex w)
w
- The specified complex number.
scale(double)
public final Complex negate()
public static Complex polarToComplex(double magnitude, double angle)
magnitude
- The magnitude.angle
- The angle.
public Complex pow(double y)
y
- The exponent, which is a double.
public static Complex pow(Complex z, double y)
z
- The number to be raised to a power.y
- The exponent.
public final Complex pow(Complex y)
y
- The exponent, which is a complex number.
public static Complex pow(Complex z, Complex y)
z
- The number to be raised to a power.y
- The exponent.
public static Complex pow(double z, Complex y)
z
- The number to be raised to a power.y
- The exponent.
public static double real(Complex z)
z
- The complex number.
public static double real(double z)
z
- The complex number.
public final Complex reciprocal()
public static Complex reciprocal(Complex z)
z
- A complex number.
public final Complex[] roots(int n)
n
- An integer that must be greater than or equal to one.
public static Complex[] roots(Complex z, int n)
z
- A complex number.n
- An integer that must be greater than or equal to one.
public final Complex scale(double scalar)
scalar
- A real number.
multiply(ptolemy.math.Complex)
public Complex sec()
sec(z) = 1/cos(z)where
z
is this complex number.
public static Complex sec(Complex z)
sec(z) = 1/cos(z)where
z
is this complex number.
z
- A complex number.
public final Complex sin()
sin(z) = (exp(i*z) - exp(-i*z))/(2*i)where
z
is this complex number.
public static Complex sin(Complex z)
sin(z) = (exp(i*z) - exp(-i*z))/(2*i)where
z
is this complex number.
z
- A complex number.
public final Complex sinh()
sinh(z) = (exp(z) - exp(-z))/2where
z
is this complex number.
public static Complex sinh(Complex z)
sinh(z) = (exp(z) - exp(-z))/2where
z
is this complex number.
z
- A complex number.
public final Complex sqrt()
sqrt(z) = sqrt(mag(z))*(cos(angle(z)/2) + i * sin(angle(z)/2) )where
z
is this complex number.
public static Complex sqrt(Complex z)
sqrt(z) = sqrt(mag(z))*(cos(angle(z)/2) + i * sin(angle(z)/2) )where
z
is this complex number.
z
- A complex number.
public final Complex subtract(Complex w)
w
- The number that is being subtracted.
public final Complex tan()
tan(z) = sin(z)/cos(z)where
z
is this complex number.
public static Complex tan(Complex z)
tan(z) = sin(z)/cos(z)where
z
is this complex number.
z
- A complex number.
public final Complex tanh()
tanh(z) = sinh(z)/cosh(z)where
z
is this complex number.
public static Complex tanh(Complex z)
tanh(z) = sinh(z)/cosh(z)where
z
is this complex number.
z
- A complex number.
public final java.lang.String toString()
toString
in class java.lang.Object
public static java.lang.String toString(Complex value)
value
- The given value.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |