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

Variable Index

 o _imaginary
 o _real

Constructor Index

 o Complex()
Default constructor creates the complex number z = (0,0)
 o Complex(double, double)
Creates the complex number z = (real, imaginary)

Method Index

 o clone()
Clone procedure
 o conjugate()
For any complex number z = (a,b) the conjugate (usually denoted z-bar) is defined as (a,-b)
 o 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.
 o equals(Complex)
Two complex numbers are equal if and only if both their real and imaginary components are equal
 o equals(Object)
Two complex numbers are equal if both their real and imaginary components are equal
 o getImaginary()
Returns the imaginary component of the complex number
 o getReal()
Returns the real component of the complex number
 o main(String[])
Tests the Complex API
 o minus(Complex)
Subtracting two complex numbers (a,b) (c,d) is defined as (a - c, b -d)
 o plus(Complex)
Adding two complex numbers (a,b) (c,d) is defined as (a+c,b+d)
 o power(int)
Return the exponant of the complex number.
 o times(Complex)
Multiplying two complex numbers (a,b) (c,d) is defined as (a*c - b*d, a*d + b*c)
 o toString()
Returns
(r,i)
where r is the real component and i is the imaginary component

Variables

 o _real
 private double _real
 o _imaginary
 private double _imaginary

Constructors

 o Complex
 public Complex()
Default constructor creates the complex number z = (0,0)

 o Complex
 public Complex(double real,
                double imaginary)
Creates the complex number z = (real, imaginary)

Methods

 o 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
 o getReal
 public double getReal()
Returns the real component of the complex number

Returns:
s the real value
 o getImaginary
 public double getImaginary()
Returns the imaginary component of the complex number

Returns:
s the imaginary value
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o clone
 public java.lang.Object clone()
Clone procedure

Returns:
s A deep copy of this
Overrides:
clone in class java.lang.Object
 o main
 public static void main(java.lang.String args[])
Tests the Complex API


All Packages  Class Hierarchy  This Package  Previous  Next  Index