org.gwoptics.mathutils
Class Complex

java.lang.Object
  extended by org.gwoptics.mathutils.Complex

public class Complex
extends java.lang.Object

Complex is a class that provides complex numbers and a number of mathematical functions (dynamic and static) such as sqrt() and exp() for complex numbers.

Since:
0.1.1
Author:
Andreas Freise 05/6/2009

Constructor Summary
Complex(double re)
          Additional constructor that returns a purely real complex number
Complex(double re, double im)
          Additional constructor that return the user defined complex number
 
Method Summary
 double abs()
          This function computes the absolute of a complex number as |z|=sqrt(x^2+y^2).
static double abs(Complex c)
          This function computes the absolute of a complex number as |c|=sqrt(x^2+y^2).
 double absSquared()
          This function returns the absolute square of a complex number as |z|^2=x^2+y^2.
static double absSquared(Complex c)
          This function computes the absolute square of a complex numbers as |c|^2=x^2+y^2.
 void add(Complex c)
          This function add a complex number to a complex number as z=z+c.
static Complex add(Complex a, Complex b)
          This function adds two complex numbers as z=a+b.
 void conj()
          This function computes the complex conjugate of a complex number.
static Complex conj(Complex z)
          This function computes the complex conjugate of a complex number
 void divide(Complex b)
          This function divides the complex number by a complex number.
static Complex divide(Complex a, Complex b)
          This function computes the division of two complex numbers
static Complex exp(Complex z)
          This function computes the exponential of a complex number exp(z).
static Complex expi(java.lang.Double phi)
          This function computes the number exp( i phi )
 double imag()
          This function returns the imaginary part of the complex number.
static double imag(Complex c)
          This function returns the imaginary part of a complex number.
 void inv()
          This function computes the inverse of the complex number
static Complex inv(Complex z)
          This function returns the inverse of a complex number
 boolean isEqual(Complex c)
          This functions tests whether the Complex number is equal to another.
static boolean isEqual(Complex a, Complex b)
          This function tests whether two Complex numbers are equal.
 boolean isNaN()
          This funtions tests whether the complex number is `not a number' NaN.
static boolean isNaN(Complex c)
          This function tests whether a complex number is `not a number' NaN.
static Complex log(Complex z)
          This function computes the logarithm of a complex number
 java.lang.Double modulus()
          This function computes the modulus of the complex number
static java.lang.Double modulus(Complex z)
          This function returns the modulus of a complex number
 void multiply(Complex b)
          This function multiplies the complex number by a complex number.
static Complex multiply(Complex a, Complex b)
          This function multiplies two complex numbers a*b.
static Complex newAbsPhi(double amp, double phi)
          This function returns a new complex number set via amplitude and phase as amp*exp(i phi).
static Complex pow(Complex z, int nom, int denom)
          This function computes a rational power of a complex number z^(nom/denom).
 double real()
          This function returns the real part of the complex number.
static double real(Complex c)
          This function returns the real part of a complex number.
 void scale(java.lang.Double x)
          This function multiplies the complex number by a real number
static Complex scale(java.lang.Double x, Complex z)
          This function multiplies a complex number by a real number
 void scaleAndDelay(double amp, double phi)
          This function multiplies the complex number by a real number and adds a phase delay as z=z*x*exp(i phi).
static Complex scaleAndDelay(double amp, double phi, Complex z)
          This function multiplies a complex number by another given by amplitude and phase as return = z * abs * exp (i phi).
 void set(double re, double im)
          This functions sets the real and imaginary part of the complex number.
 void setAbsPhi(double amp, double phi)
          This function sets the complex number via an amplitude and phase as amp*exp(i phi).
 void setImag(double im)
          This function sets the imaginary part of the complex number.
 void setReal(double re)
          This functions sets the real part of the complex number
 Complex sqrt()
          This function computes the square root of the complex number
static Complex sqrt(Complex z)
          This function returns the sqaure root of a complex number.
 void squared()
          This function computes the square of the complex number as (x + i y)*(x + i y)
static Complex squared(Complex c)
          This function computes the square of a complex number as (x + i y) * (x + i y)
 java.lang.String toString()
          This function converts a complex number into a String "x + y i" with x being the real and y the imaginary part.
static java.lang.String toString(Complex z)
          This function converts a complex number into a String "x + y i" with x being the real and y the imaginary part.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Complex

public Complex(double re,
               double im)
Additional constructor that return the user defined complex number

Parameters:
re - real part
im - imaginary part

Complex

public Complex(double re)
Additional constructor that returns a purely real complex number

Parameters:
re - real part
Method Detail

set

public void set(double re,
                double im)
This functions sets the real and imaginary part of the complex number.

Parameters:
re - real part
im - imaginary part

setReal

public void setReal(double re)
This functions sets the real part of the complex number

Parameters:
re - real part

setImag

public void setImag(double im)
This function sets the imaginary part of the complex number.

Parameters:
im - imaginary part

setAbsPhi

public void setAbsPhi(double amp,
                      double phi)
This function sets the complex number via an amplitude and phase as amp*exp(i phi).

Parameters:
amp - amplitude
phi - phase

newAbsPhi

public static Complex newAbsPhi(double amp,
                                double phi)
This function returns a new complex number set via amplitude and phase as amp*exp(i phi).

Parameters:
amp - amplitude
phi - phase
Returns:
complex number amp*exp(i phi)

add

public void add(Complex c)
This function add a complex number to a complex number as z=z+c.

Parameters:
c - complex number

add

public static Complex add(Complex a,
                          Complex b)
This function adds two complex numbers as z=a+b.

Parameters:
a - complex number
b - complex number
Returns:
complex number a+b

squared

public void squared()
This function computes the square of the complex number as (x + i y)*(x + i y)


squared

public static Complex squared(Complex c)
This function computes the square of a complex number as (x + i y) * (x + i y)

Parameters:
c - complex number
Returns:
complex number c*c

absSquared

public double absSquared()
This function returns the absolute square of a complex number as |z|^2=x^2+y^2.

Returns:
absolute squared |z|^2

absSquared

public static double absSquared(Complex c)
This function computes the absolute square of a complex numbers as |c|^2=x^2+y^2.

Parameters:
c - complex number
Returns:
absolute squared |c|^2

abs

public double abs()
This function computes the absolute of a complex number as |z|=sqrt(x^2+y^2).

Returns:
absolute |c|

abs

public static double abs(Complex c)
This function computes the absolute of a complex number as |c|=sqrt(x^2+y^2).

Parameters:
c - complex number
Returns:
absolute |c|

real

public double real()
This function returns the real part of the complex number.

Returns:
real part

real

public static double real(Complex c)
This function returns the real part of a complex number.

Parameters:
c - complex number
Returns:
real part

imag

public double imag()
This function returns the imaginary part of the complex number.

Returns:
imaginary part

imag

public static double imag(Complex c)
This function returns the imaginary part of a complex number.

Parameters:
c - complex number
Returns:
imaginary part

sqrt

public Complex sqrt()
This function computes the square root of the complex number

Returns:
square root

sqrt

public static Complex sqrt(Complex z)
This function returns the sqaure root of a complex number.

Parameters:
z - complex number
Returns:
square root

inv

public void inv()
This function computes the inverse of the complex number


inv

public static Complex inv(Complex z)
This function returns the inverse of a complex number

Parameters:
z - complex number
Returns:
inverse

modulus

public java.lang.Double modulus()
This function computes the modulus of the complex number

Returns:
modulus

modulus

public static java.lang.Double modulus(Complex z)
This function returns the modulus of a complex number

Parameters:
z - complex number
Returns:
modulus

multiply

public void multiply(Complex b)
This function multiplies the complex number by a complex number.

Parameters:
b - complex number

multiply

public static Complex multiply(Complex a,
                               Complex b)
This function multiplies two complex numbers a*b.

Parameters:
a - complex number
b - complex number
Returns:
multiplication a*b

divide

public void divide(Complex b)
This function divides the complex number by a complex number.

Parameters:
b - complex number

divide

public static Complex divide(Complex a,
                             Complex b)
This function computes the division of two complex numbers

Parameters:
a - complex number
b - complex number
Returns:
division a/b

conj

public void conj()
This function computes the complex conjugate of a complex number.


conj

public static Complex conj(Complex z)
This function computes the complex conjugate of a complex number

Parameters:
z - complex number
Returns:
complex conjugate z^*

scale

public void scale(java.lang.Double x)
This function multiplies the complex number by a real number

Parameters:
x - multiplier (real number)

scale

public static Complex scale(java.lang.Double x,
                            Complex z)
This function multiplies a complex number by a real number

Parameters:
x - multiplier (real number)
z - complex number
Returns:
complex number x*z

scaleAndDelay

public void scaleAndDelay(double amp,
                          double phi)
This function multiplies the complex number by a real number and adds a phase delay as z=z*x*exp(i phi).

Parameters:
amp - multiplier (real number)
phi - phase [rad]

scaleAndDelay

public static Complex scaleAndDelay(double amp,
                                    double phi,
                                    Complex z)
This function multiplies a complex number by another given by amplitude and phase as return = z * abs * exp (i phi).

Parameters:
amp -
phi -
z -
Returns:
multiplication z*amp*exp(i phi)

pow

public static Complex pow(Complex z,
                          int nom,
                          int denom)
This function computes a rational power of a complex number z^(nom/denom).

Parameters:
z - complex number
nom - nomiator of exponent
denom - denominator of exponent
Returns:
rational power z^(nom/denom)

log

public static Complex log(Complex z)
This function computes the logarithm of a complex number

Parameters:
z - complex number
Returns:
logarithm log(z)

exp

public static Complex exp(Complex z)
This function computes the exponential of a complex number exp(z).

Parameters:
z - complex number
Returns:
exponential exp(z)

expi

public static Complex expi(java.lang.Double phi)
This function computes the number exp( i phi )

Parameters:
phi - phase
Returns:
complex number

isNaN

public boolean isNaN()
This funtions tests whether the complex number is `not a number' NaN. If the real or imaginary part is NaN this function returns `true'.

Returns:
true if NaN

isNaN

public static boolean isNaN(Complex c)
This function tests whether a complex number is `not a number' NaN. If the real or the imaginary part is NaN this function returns true.

Parameters:
c - complex number
Returns:
true of c is NaN

isEqual

public boolean isEqual(Complex c)
This functions tests whether the Complex number is equal to another.

Parameters:
c - complex number
Returns:
retruns true if number is equal to c

isEqual

public static boolean isEqual(Complex a,
                              Complex b)
This function tests whether two Complex numbers are equal.

Parameters:
a - complex number
b - complex number
Returns:
true if a is equal to b

toString

public java.lang.String toString()
This function converts a complex number into a String "x + y i" with x being the real and y the imaginary part.

Overrides:
toString in class java.lang.Object
Returns:
string

toString

public static java.lang.String toString(Complex z)
This function converts a complex number into a String "x + y i" with x being the real and y the imaginary part.

Parameters:
z - complex number
Returns:
string


processing library gwoptics by Daniel Brown and Andreas Freise. (c) 2009 onwards