All Packages Class Hierarchy This Package Previous Next Index
Class cmpsci197c.Complex
java.lang.Object
|
+----cmpsci197c.Complex
- public class Complex
- extends java.lang.Object
Simple complex number class.
A complex number z = (x,y) has both a real component x and
an imaginary component y. Often z is written as x +iy where
i is the solution to v^2 = -1.
- Author:
- Brent Heeringa
-
_imaginary
-
-
_real
-
-
Complex()
- Default constructor creates the complex number z = (0,0)
-
Complex(double, double)
- Creates the complex number z = (real, imaginary)
-
clone()
- Clone procedure
-
conjugate()
- For any complex number z = (a,b) the conjugate
(usually denoted z-bar) is defined as (a,-b)
-
divide(Complex)
- Dividing two complex numbers z = (a,b) w = (c,d) is defined as
z * w-bar / |w|^2
The |w|^2 is equivalent to w * w.conjugate() where
the conjugate of w = (c,d) is defined as (c,-d)
Note that multiplying by the conjugate produces a non-negative real
number so that we can easily divide the real and imaginary
components of the imaginary numbers.
-
equals(Complex)
- Two complex numbers are equal if and only if both their
real and imaginary components are equal
-
equals(Object)
- Two complex numbers are equal if both their
real and imaginary components are equal
-
getImaginary()
- Returns the imaginary component of the complex number
-
getReal()
- Returns the real component of the complex number
-
main(String[])
- Tests the Complex API
-
minus(Complex)
- Subtracting two complex numbers (a,b) (c,d) is defined as
(a - c, b -d)
-
plus(Complex)
- Adding two complex numbers (a,b) (c,d) is defined as
(a+c,b+d)
-
power(int)
- Return the exponant of the complex number.
-
times(Complex)
- Multiplying two complex numbers (a,b) (c,d) is defined as
(a*c - b*d, a*d + b*c)
-
toString()
- Returns
(r,i)
where r is the real
component and i is the imaginary component
_real
private double _real
_imaginary
private double _imaginary
Complex
public Complex()
- Default constructor creates the complex number z = (0,0)
Complex
public Complex(double real,
double imaginary)
- Creates the complex number z = (real, imaginary)
plus
public cmpsci197c.Complex plus(cmpsci197c.Complex c)
- Adding two complex numbers (a,b) (c,d) is defined as
(a+c,b+d)
- Returns:
- s this + c
getReal
public double getReal()
- Returns the real component of the complex number
- Returns:
- s the real value
getImaginary
public double getImaginary()
- Returns the imaginary component of the complex number
- Returns:
- s the imaginary value
minus
public cmpsci197c.Complex minus(cmpsci197c.Complex c)
- Subtracting two complex numbers (a,b) (c,d) is defined as
(a - c, b -d)
- Returns:
- s this - c
times
public cmpsci197c.Complex times(cmpsci197c.Complex c)
- Multiplying two complex numbers (a,b) (c,d) is defined as
(a*c - b*d, a*d + b*c)
- Returns:
- s this * c
divide
public cmpsci197c.Complex divide(cmpsci197c.Complex c) throws java.lang.ArithmeticException
- Dividing two complex numbers z = (a,b) w = (c,d) is defined as
z * w-bar / |w|^2
The |w|^2 is equivalent to w * w.conjugate() where
the conjugate of w = (c,d) is defined as (c,-d)
Note that multiplying by the conjugate produces a non-negative real
number so that we can easily divide the real and imaginary
components of the imaginary numbers.
- Returns:
- s this / c
power
public cmpsci197c.Complex power(int power)
- Return the exponant of the complex number.
Note that when power = 0 we return (1,0)
and when power < 0 we return 1 / (a,b)^power
- Returns:
- s this^power
conjugate
public cmpsci197c.Complex conjugate()
- For any complex number z = (a,b) the conjugate
(usually denoted z-bar) is defined as (a,-b)
- Returns:
- s The conjugate of this
equals
public boolean equals(cmpsci197c.Complex c)
- Two complex numbers are equal if and only if both their
real and imaginary components are equal
- Returns:
- s true if this is equivalent to c
equals
public boolean equals(java.lang.Object o)
- Two complex numbers are equal if both their
real and imaginary components are equal
- Returns:
- s true if this is equivalent to o
- Overrides:
- equals in class java.lang.Object
toString
public java.lang.String toString()
- Returns
(r,i)
where r is the real
component and i is the imaginary component
- Returns:
- s String representation of this
- Overrides:
- toString in class java.lang.Object
clone
public java.lang.Object clone()
- Clone procedure
- Returns:
- s A deep copy of this
- Overrides:
- clone in class java.lang.Object
main
public static void main(java.lang.String args[])
- Tests the Complex API
All Packages Class Hierarchy This Package Previous Next Index