org.encog.mathutil

## Class ComplexNumber

• ```public class ComplexNumber
extends Object```
A complex number class. This class is based on source code by Andrew G. Bennett, Department of Mathematics Kansas State University The original version can be found here: http://www.math.ksu.edu/~bennett/jomacg/c.html
• ### Constructor Summary

Constructors
Constructor and Description
`ComplexNumber(ComplexNumber other)`
Create a complex number from another complex number.
```ComplexNumber(double u, double v)```
Constructs the complex number z = u + i*v
• ### Method Summary

Methods
Modifier and Type Method and Description
`double` `arg()`
Argument of this Complex number (the angle in radians with the x-axis in polar coordinates).
`ComplexNumber` `chs()`
Negative of this complex number (chs stands for change sign).
`ComplexNumber` `conj()`
Complex conjugate of this Complex number (the conjugate of x+i*y is x-i*y).
`ComplexNumber` `cos()`
Cosine of this Complex number (doesn't change this Complex number).
`ComplexNumber` `cosh()`
Hyperbolic cosine of this Complex number (doesn't change this Complex number).
`ComplexNumber` `div(ComplexNumber w)`
Division of Complex numbers (doesn't change this Complex number).
`ComplexNumber` `exp()`
Complex exponential (doesn't change this Complex number).
`double` `getImaginary()`
Imaginary part of this Complex number (the y-coordinate in rectangular coordinates).
`double` `getReal()`
Real part of this Complex number (the x-coordinate in rectangular coordinates).
`ComplexNumber` `log()`
Principal branch of the Complex logarithm of this Complex number.
`ComplexNumber` `minus(ComplexNumber w)`
Subtraction of Complex numbers (doesn't change this Complex number).
`double` `mod()`
Modulus of this Complex number (the distance from the origin in polar coordinates).
`ComplexNumber` `plus(ComplexNumber w)`
Addition of Complex numbers (doesn't change this Complex number).
`ComplexNumber` `sin()`
Sine of this Complex number (doesn't change this Complex number).
`ComplexNumber` `sinh()`
Hyperbolic sine of this Complex number (doesn't change this Complex number).
`ComplexNumber` `sqrt()`
Complex square root (doesn't change this complex number).
`ComplexNumber` `tan()`
Tangent of this Complex number (doesn't change this Complex number).
`ComplexNumber` `times(ComplexNumber w)`
Complex multiplication (doesn't change this Complex number).
`String` `toString()`
String representation of this Complex number.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Constructor Detail

• #### ComplexNumber

```public ComplexNumber(double u,
double v)```
Constructs the complex number z = u + i*v
Parameters:
`u` - Real part
`v` - Imaginary part
• #### ComplexNumber

`public ComplexNumber(ComplexNumber other)`
Create a complex number from another complex number.
Parameters:
`other` - The other complex number.
• ### Method Detail

• #### getReal

`public double getReal()`
Real part of this Complex number (the x-coordinate in rectangular coordinates).
Returns:
Re[z] where z is this Complex number.
• #### getImaginary

`public double getImaginary()`
Imaginary part of this Complex number (the y-coordinate in rectangular coordinates).
Returns:
Im[z] where z is this Complex number.
• #### mod

`public double mod()`
Modulus of this Complex number (the distance from the origin in polar coordinates).
Returns:
|z| where z is this Complex number.
• #### arg

`public double arg()`
Argument of this Complex number (the angle in radians with the x-axis in polar coordinates).
Returns:
arg(z) where z is this Complex number.
• #### conj

`public ComplexNumber conj()`
Complex conjugate of this Complex number (the conjugate of x+i*y is x-i*y).
Returns:
z-bar where z is this Complex number.
• #### plus

`public ComplexNumber plus(ComplexNumber w)`
Addition of Complex numbers (doesn't change this Complex number).
(x+i*y) + (s+i*t) = (x+s)+i*(y+t).
Parameters:
`w` - is the number to add.
Returns:
z+w where z is this Complex number.
• #### minus

`public ComplexNumber minus(ComplexNumber w)`
Subtraction of Complex numbers (doesn't change this Complex number).
(x+i*y) - (s+i*t) = (x-s)+i*(y-t).
Parameters:
`w` - is the number to subtract.
Returns:
z-w where z is this Complex number.
• #### times

`public ComplexNumber times(ComplexNumber w)`
Complex multiplication (doesn't change this Complex number).
Parameters:
`w` - is the number to multiply by.
Returns:
z*w where z is this Complex number.
• #### div

`public ComplexNumber div(ComplexNumber w)`
Division of Complex numbers (doesn't change this Complex number).
(x+i*y)/(s+i*t) = ((x*s+y*t) + i*(y*s-y*t)) / (s^2+t^2)
Parameters:
`w` - is the number to divide by
Returns:
new Complex number z/w where z is this Complex number
• #### exp

`public ComplexNumber exp()`
Complex exponential (doesn't change this Complex number).
Returns:
exp(z) where z is this Complex number.
• #### log

`public ComplexNumber log()`
Principal branch of the Complex logarithm of this Complex number. (doesn't change this Complex number). The principal branch is the branch with -pi < arg <= pi.
Returns:
log(z) where z is this Complex number.
• #### sqrt

`public ComplexNumber sqrt()`
Complex square root (doesn't change this complex number). Computes the principal branch of the square root, which is the value with 0 <= arg < pi.
Returns:
sqrt(z) where z is this Complex number.
• #### sin

`public ComplexNumber sin()`
Sine of this Complex number (doesn't change this Complex number).
sin(z) = (exp(i*z)-exp(-i*z))/(2*i).
Returns:
sin(z) where z is this Complex number.
• #### cos

`public ComplexNumber cos()`
Cosine of this Complex number (doesn't change this Complex number).
cos(z) = (exp(i*z)+exp(-i*z))/ 2.
Returns:
cos(z) where z is this Complex number.
• #### sinh

`public ComplexNumber sinh()`
Hyperbolic sine of this Complex number (doesn't change this Complex number).
sinh(z) = (exp(z)-exp(-z))/2.
Returns:
sinh(z) where z is this Complex number.
• #### cosh

`public ComplexNumber cosh()`
Hyperbolic cosine of this Complex number (doesn't change this Complex number).
cosh(z) = (exp(z) + exp(-z)) / 2.
Returns:
cosh(z) where z is this Complex number.
• #### tan

`public ComplexNumber tan()`
Tangent of this Complex number (doesn't change this Complex number).
tan(z) = sin(z)/cos(z).
Returns:
tan(z) where z is this Complex number.
• #### chs

`public ComplexNumber chs()`
Negative of this complex number (chs stands for change sign). This produces a new Complex number and doesn't change this Complex number.
-(x+i*y) = -x-i*y.
Returns:
-z where z is this Complex number.
• #### toString

`public String toString()`
String representation of this Complex number.
Overrides:
`toString` in class `Object`
Returns:
x+i*y, x-i*y, x, or i*y as appropriate.