Class Complex
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondouble
abs()
Returns the absolute value of the complex number.double
abs2()
Returns the square of the absolute value (re*re+im*im).acos()
acosh()
add
(double d) Returns the sum of a complex number and a doubleReturns the sum of two complex numbersdouble
arg()
Returns the argument of this complex number (Math.atan2(re,im))asin()
asinh()
atan()
atanh()
static Complex
cart
(double re, double im) Returns a Complex from real and imaginary parts.Convert polar to CartesianConjugats the complex numbercos()
Returns the cosine of this complex number.cosh()
div
(double d) Devide the complex number by a double value.Returns the result of dividing this complex number by the parameter.boolean
Compares this object with the Complex number given as parameterexp()
Returns e to the power of the complex numberdouble
im()
Returns the imaginary component of this objectinvert()
boolean
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 Not-a-Number (NaN) value.log()
Returns the logarithm of this complex number.double
mag()
Returns the magnitude of the complex numbermul
(double b) Multiplies the complex number with a double value.Multiplies the complex number with another complex value.neg()
Returns the negative value of this complex number.static Complex
Convert text representation to a Complex.polar()
Convert Cartesian to polarstatic Complex
Returns the base raised to the power of the Complex exponent.static Complex
static Complex
Returns the Complex base raised to the power of the Complex exponent.power
(double exponent) Returns the value of this complex number raised to the power of a real component (in double precision).Returns the value of this complex number raised to the power of a complex exponentdouble
re()
Returns the real component of this objectvoid
set
(double re_in, double im_in) Sets the real and imaginary values of the object.void
Copies the values from the parameter object to this objectvoid
setIm
(double im_in) Sets the imaginary component of the objectvoid
setRe
(double re_in) Sets the real component of the objectsin()
Returns the sine of this complex number.sinh()
sqrt()
Calculates the square root of this object.subtract
(double d) Subtracts the double d from the complex number Returns the subtraction of complex z from a complex numberReturns the subtraction of complex z from a complex numbertan()
Returns the tangent of this complex number.tanh()
toString()
Returns the value of this complex number as a string in the format:
-
Constructor Details
-
Complex
public Complex()Default constructor. -
Complex
public Complex(double re_in) Constructor from a single double value. The complex number is initialized with the real component equal to the parameter, and the imaginary component equal to zero.- Parameters:
re_in
-
-
Complex
Construct from a Number. This constructor uses the doubleValue() method of the parameter to initialize the real component of the complex number. The imaginary component is initialized to zero.- Parameters:
re_in
-
-
Complex
Copy constructor- Parameters:
z
-
-
Complex
public Complex(double re_in, double im_in) Initialize the real and imaginary components to the values given by the parameters.- Parameters:
re_in
-im_in
-
-
-
Method Details
-
polar
Convert Cartesian to polar -
cartesian
Convert polar to Cartesian -
re
public double re()Returns the real component of this object -
im
public double im()Returns the imaginary component of this object -
set
Copies the values from the parameter object to this object -
set
public void set(double re_in, double im_in) Sets the real and imaginary values of the object. -
setRe
public void setRe(double re_in) Sets the real component of the object -
setIm
public void setIm(double im_in) Sets the imaginary component of the object -
equals
Compares this object with the Complex number given as parameterb
. Thetolerance
parameter is the radius within which theb
number must lie for the two complex numbers to be considered equal.- Returns:
true
if the complex number are considered equal,false
otherwise.
-
toString
Returns the value of this complex number as a string in the format:(real, imaginary)
. -
abs
public double abs()Returns the absolute value of the complex number. -
abs2
public double abs2()Returns the square of the absolute value (re*re+im*im). -
mag
public double mag()Returns the magnitude of the complex number -
arg
public double arg()Returns the argument of this complex number (Math.atan2(re,im)) -
parseComplex
Convert text representation to a Complex. input format (real_double,imaginary_double) -
add
Returns the sum of two complex numbers -
add
Returns the sum of a complex number and a double -
subtract
Returns the subtraction of complex z from a complex number -
subtract
Subtracts the double d from the complex number Returns the subtraction of complex z from a complex number -
neg
Returns the negative value of this complex number. -
mul
Multiplies the complex number with a double value.- Returns:
- The result of the multiplication
-
mul
Multiplies the complex number with another complex value.- Returns:
- The result of the multiplication
-
div
Returns the result of dividing this complex number by the parameter. -
div
Devide the complex number by a double value.- Returns:
- The result of the division
-
invert
-
conjugate
Conjugats the complex number -
power
Returns the value of this complex number raised to the power of a real component (in double precision).This method considers special cases where a simpler algorithm would return "ugly" results.
For example when the expression (-1e40)^0.5 is evaluated without considering the special case, the argument of the base is the double number closest to pi. When sin and cos are used for the final evaluation of the result, the slight difference of the argument from pi causes a non-zero value for the real component of the result. Because the value of the base is so high, the error is magnified.Although the error is normal for floating point calculations, the consideration of commonly occurring special cases improves the accuracy and esthetics of the results.If you know a more elegant way to solve this problem, please let me know at nathanfunk@hotmail.com .
-
cart
Returns a Complex from real and imaginary parts. -
power
Returns the value of this complex number raised to the power of a complex exponent -
pow
-
pow
Returns the base raised to the power of the Complex exponent. -
pow
Returns the Complex base raised to the power of the Complex exponent. -
exp
Returns e to the power of the complex number -
log
Returns the logarithm of this complex number. -
sqrt
Calculates the square root of this object. -
sin
Returns the sine of this complex number. -
cos
Returns the cosine of this complex number. -
tan
Returns the tangent of this complex number. -
asin
-
acos
-
atan
-
sinh
-
cosh
-
tanh
-
asinh
-
acosh
-
atanh
-
isInfinite
public boolean isInfinite()Returns true if either the real or imaginary component of this Complex is an infinite value.- Returns:
- true if either component of the Complex object is infinite; false, otherwise.
-
isNaN
public boolean isNaN()Returns true if either the real or imaginary component of this Complex is a Not-a-Number (NaN) value.- Returns:
- true if either component of the Complex object is NaN; false, otherwise.
-