

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object org.netlib.math.complex.Complex
public class Complex
Field Summary  

static java.lang.String 
AUTHOR

static java.lang.String 
DATE

static Complex 
iii
A constant representing i, the famous square root of 1. 
double 
im

double 
re

static java.lang.String 
REMARK

protected static double 
TWO_PI
Twice PI radians is the same thing as 360 degrees. 
static java.lang.String 
VERSION

Constructor Summary  

Complex()
Constructs a Complex representing the number zero. 

Complex(Complex z)
Constructs a separate new Complex from an existing Complex. 

Complex(double re)
Constructs a Complex representing a real number. 

Complex(double re,
double im)
Constructs a Complex from real and imaginary parts. 
Method Summary  

double 
abs()
Returns the magnitude of a Complex number. 
Complex 
acos()
Returns the principal arc cosine of a Complex number. 
Complex 
acosh()
Returns the principal inverse hyperbolic cosine of a Complex number. 
Complex 
add(Complex z)
To perform z1 + z2, you write z1.add(z2) . 
double 
arg()
Returns the principal angle of a Complex number, in radians, measured counterclockwise from the real axis. 
Complex 
asin()
Returns the principal arc sine of a Complex number. 
Complex 
asinh()
Returns the principal inverse hyperbolic sine of a Complex number. 
Complex 
atan()
Returns the principal arc tangent of a Complex number. 
Complex 
atanh()
Returns the principal inverse hyperbolic tangent of a Complex number. 
static Complex 
cart(double re,
double im)
Returns a Complex from real and imaginary parts. 
java.lang.Object 
clone()
Overrides the Cloneable interface. 
Complex 
conj()
Returns the Complex "conjugate". 
Complex 
cos()
Returns the cosine of a Complex number. 
Complex 
cosec()
Returns the cosecant of a Complex number. 
Complex 
cosh()
Returns the hyperbolic cosine of a Complex number. 
Complex 
cot()
Returns the cotangent of a Complex number. 
Complex 
div(Complex z)
To perform z1 / z2, you write z1.div(z2) . 
boolean 
equals(Complex z,
double tolerance)
Decides if two Complex numbers are "sufficiently" alike to be considered equal. 
Complex 
exp()
Returns the number e "raised to" a Complex power. 
double 
im()
Extracts the imaginary part of a Complex as a double. 
boolean 
isInfinite()
Returns true if either the real or imaginary component of this Complex is an infinite value. 
boolean 
isNaN()
Returns true if either the real or imaginary component of this Complex is a NotaNumber (NaN) value. 
Complex 
log()
Returns the principal natural logarithm of a Complex number. 
static void 
main(java.lang.String[] args)
Useful for checking up on the exact version. 
Complex 
mul(Complex z)
To perform z1 * z2, you write z1.mul(z2) . 
Complex 
neg()
Returns the "negative" of a Complex number. 
double 
norm()
Returns the square of the "length" of a Complex number. 
static Complex 
polar(double r,
double theta)
Returns a Complex from a size and direction. 
Complex 
pow(Complex exponent)
Returns this Complex raised to the power of a Complex exponent. 
static Complex 
pow(Complex base,
Complex exponent)
Returns the Complex base raised to the power of the Complex exponent. 
static Complex 
pow(Complex base,
double exponent)
Returns the Complex base raised to the power of the exponent. 
static Complex 
pow(double base,
Complex exponent)
Returns the base raised to the power of the Complex exponent. 
double 
re()
Extracts the real part of a Complex as a double. 
static Complex 
real(double real)
Returns a Complex representing a real number. 
Complex 
scale(double scalar)
Returns the Complex scaled by a real number. 
Complex 
sec()
Returns the secant of a Complex number. 
Complex 
sin()
Returns the sine of a Complex number. 
Complex 
sinh()
Returns the hyperbolic sine of a Complex number. 
Complex 
sqrt()
Returns a Complex representing one of the two square roots. 
Complex 
sub(Complex z)
To perform z1  z2, you write z1.sub(z2) . 
Complex 
tan()
Returns the tangent of a Complex number. 
Complex 
tanh()
Returns the hyperbolic tangent of a Complex number. 
java.lang.String 
toString()
Converts a Complex into a String of the form
(a + bi). 
Methods inherited from class java.lang.Object 

equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait 
Field Detail 

public static final java.lang.String VERSION
public static final java.lang.String DATE
public static final java.lang.String AUTHOR
public static final java.lang.String REMARK
protected static final double TWO_PI
public static final Complex iii
The other square root of 1 is  i.
public double re
public double im
Constructor Detail 

public Complex()
public Complex(double re)
re
 The real number
real(double)
public Complex(Complex z)
z
 A Complex number
public Complex(double re, double im)
Note:
re
 Real partim
 Imaginary part
cart(double, double)
,
polar(double, double)
Method Detail 

public static void main(java.lang.String[] args)
public static Complex real(double real)
real
 The real number
re()
,
cart(double, double)
public static Complex cart(double re, double im)
re
 Real partim
 Imaginary part
re()
,
im()
,
polar(double, double)
,
toString()
public static Complex polar(double r, double theta)
r
 Sizetheta
 Direction (in radians)
abs()
,
arg()
,
cart(double, double)
public static Complex pow(Complex base, double exponent)
base
 The base "to raise"exponent
 The exponent "by which to raise"
pow(double, Complex)
public static Complex pow(double base, Complex exponent)
base
 The base "to raise"exponent
 The exponent "by which to raise"
pow(Complex, Complex)
,
exp()
public static Complex pow(Complex base, Complex exponent)
base
 The base "to raise"exponent
 The exponent "by which to raise"
pow(Complex, double)
,
pow(Complex)
public boolean isInfinite()
public boolean isNaN()
public boolean equals(Complex z, double tolerance)
tolerance is the maximum magnitude of the difference between them before they are considered not equal.
Checking for equality between two real numbers on computer hardware is a tricky business. Try
System.out.println((1.0/3.0 * 3.0));
and you'll see the nature of the problem! It's just as tricky with Complex numbers.
Realize that because of these complications, it's possible to find that the magnitude of one Complex number a is less than another, b, and yet a.equals(b, myTolerance) returns true. Be aware!
z
 The Complex to compare withtolerance
 The tolerance for equality
public java.lang.Object clone()
Cloneable
interface.
Standard override; no change in semantics.
The following Java code example illustrates how to clone, or copy, a Complex number:
Complex z1 = new Complex(0, 1); Complex z2 = (Complex) z1.clone();
clone
in class java.lang.Object
Cloneable
,
Object.clone()
public double re()
re(x + i*y) = x
im()
,
cart(double, double)
,
real(double)
public double im()
im(x + i*y) = y
re()
,
cart(double, double)
public double norm()
norm(x + i*y) = x*x + y*y
Always nonnegative.
abs()
public double abs()
abs(z) = sqrt(norm(z))
In other words, it's Pythagorean distance from the origin (0 + 0i, or zero).
The magnitude is also referred to as the "modulus" or "length".
Always nonnegative.
arg()
,
polar(double, double)
,
norm()
public double arg()
There are infinitely many solutions, besides the principal solution. If A is the principal solution of arg(z), the others are of the form:
A + 2*k*PI
where k is any integer.
arg() always returns a double between PI and +PI.
Note:
Domain Restrictions:
abs()
,
polar(double, double)
public Complex neg()
neg(a + i*b) = a  i*b
The magnitude of the negative is the same, but the angle is flipped through PI (or 180 degrees).
scale(double)
public Complex conj()
conj(x + i*y) = x  i*y
The conjugate appears "flipped" across the real axis.
public Complex scale(double scalar)
scale((x + i*y), s) = (x*s + i*y*s)
Scaling by the real number 2.0, doubles the magnitude, but leaves the arg() unchanged. Scaling by 1.0 keeps the magnitude the same, but flips the arg() by PI (180 degrees).
scalar
 A real number scale factor
mul(Complex)
,
div(Complex)
,
neg()
public Complex add(Complex z)
(a + i*b) + (c + i*d) = ((a+c) + i*(b+d))
public Complex sub(Complex z)
(a + i*b)  (c + i*d) = ((ac) + i*(bd))
public Complex mul(Complex z)
(a + i*b) * (c + i*d) = ( (a*c)  (b*d) + i*((a*d) + (b*c)) )
scale(double)
public Complex div(Complex z)
(a + i*b) / (c + i*d) = ( (a*c) + (b*d) + i*((b*c)  (a*d)) ) / norm(c + i*d)
Take care not to divide by zero!
Note:
Domain Restrictions:
scale(double)
public Complex sqrt()
sqrt(z) = sqrt(abs(z)) * ( cos(arg(z)/2) + i * sin(arg(z)/2) )
For any complex number z, sqrt(z) will return the complex root whose arg is arg(z)/2.
Note:
pow(Complex, double)
public Complex pow(Complex exponent)
exponent
 The exponent "by which to raise"
pow(Complex, Complex)
public Complex exp()
exp(x + i*y) = exp(x) * ( cos(y) + i * sin(y) )
Note:
Also, the following is quietly amazing:
e^{PI*i} =  1
log()
,
pow(double, Complex)
public Complex log()
log(z) = log(abs(z)) + i * arg(z)
There are infinitely many solutions, besides the principal solution. If L is the principal solution of log(z), the others are of the form:
L + (2*k*PI)*i
where k is any integer.
exp()
public Complex sin()
sin(z) = ( exp(i*z)  exp(i*z) ) / (2*i)
asin()
,
sinh()
,
cosec()
,
cos()
,
tan()
public Complex cos()
cos(z) = ( exp(i*z) + exp(i*z) ) / 2
acos()
,
cosh()
,
sec()
,
sin()
,
tan()
public Complex tan()
tan(z) = sin(z) / cos(z)
Domain Restrictions:
atan()
,
tanh()
,
cot()
,
sin()
,
cos()
public Complex cosec()
cosec(z) = 1 / sin(z)
Domain Restrictions:
sin()
,
sec()
,
cot()
public Complex sec()
sec(z) = 1 / cos(z)
Domain Restrictions:
cos()
,
cosec()
,
cot()
public Complex cot()
cot(z) = 1 / tan(z)
Domain Restrictions:
tan()
,
cosec()
,
sec()
public Complex sinh()
sinh(z) = ( exp(z)  exp(z) ) / 2
sin()
,
asinh()
public Complex cosh()
cosh(z) = ( exp(z) + exp(z) ) / 2
cos()
,
acosh()
public Complex tanh()
tanh(z) = sinh(z) / cosh(z)
tan()
,
atanh()
public Complex asin()
asin(z) = i * log(i*z + sqrt(1  z*z))
There are infinitely many solutions, besides the principal solution. If A is the principal solution of asin(z), the others are of the form:
k*PI + (1)^{k} * A
where k is any integer.
sin()
,
sinh()
public Complex acos()
acos(z) = i * log( z + i * sqrt(1  z*z) )
There are infinitely many solutions, besides the principal solution. If A is the principal solution of acos(z), the others are of the form:
2*k*PI +/ A
where k is any integer.
cos()
,
cosh()
public Complex atan()
atan(z) = i/2 * log( (iz)/(i+z) )
There are infinitely many solutions, besides the principal solution. If A is the principal solution of atan(z), the others are of the form:
A + k*PI
where k is any integer.
Domain Restrictions:
tan()
,
tanh()
public Complex asinh()
asinh(z) = log(z + sqrt(z*z + 1))
There are infinitely many solutions, besides the principal solution. If A is the principal solution of asinh(z), the others are of the form:
k*PI*i + (1)^{k} * A
where k is any integer.
sinh()
public Complex acosh()
acosh(z) = log(z + sqrt(z*z  1))
There are infinitely many solutions, besides the principal solution. If A is the principal solution of acosh(z), the others are of the form:
2*k*PI*i +/ A
where k is any integer.
cosh()
public Complex atanh()
atanh(z) = 1/2 * log( (1+z)/(1z) )
There are infinitely many solutions, besides the principal solution. If A is the principal solution of atanh(z), the others are of the form:
A + k*PI*i
where k is any integer.
Domain Restrictions:
tanh()
public java.lang.String toString()
String
of the form
(a + bi).
This enables a Complex to be easily printed. For example, if z was 2  5i, then
System.out.println("z = " + z);would print something like
z = (2.0  5.0i)
toString
in class java.lang.Object
String
containing the cartesian coordinate representation
cart(double, double)


PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 