SciLib.Math
Class complexVector

java.lang.Object
  extended by SciLib.Math.complexVector

public class complexVector
extends java.lang.Object

This class contains some methods to handle a vector of complex numbers.


Field Summary
 complex[] v
           
 
Constructor Summary
complexVector()
          Allocates a new complexVector containing no data.
complexVector(complex[] x)
          Make a complexVector from an array of complex numbers.
complexVector(complexVector x)
          Make a complexVector from another complex vector x.
complexVector(int n)
          Allocates a new complexVector of length n.
complexVector(vector x)
          Make a complexVector from a real vector x.
 
Method Summary
 vector abs()
          Make a real vector that contains the absolute values of all elements in the vector.
 void add(complex x)
          add a complex number to the vector.
 void add(double x, double y)
          add a complex number (x, y) to the vector.
 vector angle()
          Make a real vector that contains angles in radian of all elements in the vector.
 void conj()
          Change the vector to its conjugates.
 complex elementAt(int index)
          return a complex number at index "index".
 vector imaginary()
          Make a real vector with the imaginary parts of all elements in the vector.
 void load(java.lang.String fileName)
          Load data from a file to a complex vector.
 vector magnitude()
          Make a real vector that contains the absolute values of all elements in the vector.
 void print()
          Print all elements of the complex vector using System.out.
 void print(int n)
          print all elements of the complex vector with n decimal digits using System.out.
 void read(java.lang.String fileName)
          Read data from a file to a complex vector.
 vector real()
          Make a real vector with the real parts of all elements in the vector.
 void resize(int n)
          Change the size of the vector to n.
static complexVector roundUp(complexVector x, int n)
          RoundUp a complex vector x to another vector whose elements have n decimal digits
 void roundUp(int n)
          Round up this complex vector with n decimal format.
 void scale(double s)
          Scale the vector with a factor s.
 void setElementAt(complex x, int index)
          Change the value of the complex number at index "index" to x.
 int size()
          return the length of the vector.
 java.lang.String toString()
          create a String that contains the elements of the vector with n decimal digits format.
 java.lang.String toString(int n)
          create a String that contains the elements of the vector with n decimal digits format.
 void trimToSize()
          Remove all the unused elements of the vector.
 void write(java.lang.String fileName)
          Write all elements of the vector to a file.
 void write(java.lang.String fileName, int n)
          Write all elements of the vector to a file with the n deimal digits format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

v

public complex[] v
Constructor Detail

complexVector

public complexVector()
Allocates a new complexVector containing no data.


complexVector

public complexVector(int n)
Allocates a new complexVector of length n.

Parameters:
n - An integer

complexVector

public complexVector(vector x)
Make a complexVector from a real vector x.

Parameters:
x - A vector

complexVector

public complexVector(complexVector x)
Make a complexVector from another complex vector x.

Parameters:
x - A complexVector

complexVector

public complexVector(complex[] x)
Make a complexVector from an array of complex numbers.

Parameters:
x - A complexVector
Method Detail

elementAt

public complex elementAt(int index)
                  throws java.lang.ArrayIndexOutOfBoundsException
return a complex number at index "index".

Parameters:
index - An integer
Returns:
A comlex number
Throws:
java.lang.ArrayIndexOutOfBoundsException

setElementAt

public void setElementAt(complex x,
                         int index)
                  throws java.lang.ArrayIndexOutOfBoundsException
Change the value of the complex number at index "index" to x.

Parameters:
index - An integer
x - A comlex number
Throws:
java.lang.ArrayIndexOutOfBoundsException

add

public void add(complex x)
add a complex number to the vector.

Parameters:
x - A comlex number

add

public void add(double x,
                double y)
add a complex number (x, y) to the vector.

Parameters:
x - The real part of the comlex number
y - The imaginary part of the comlex number

size

public final int size()
return the length of the vector.


angle

public final vector angle()
Make a real vector that contains angles in radian of all elements in the vector.

Returns:
A vector

real

public final vector real()
Make a real vector with the real parts of all elements in the vector.

Returns:
A vector

imaginary

public final vector imaginary()
Make a real vector with the imaginary parts of all elements in the vector.

Returns:
A vector

abs

public final vector abs()
Make a real vector that contains the absolute values of all elements in the vector.

Returns:
A vector

magnitude

public final vector magnitude()
Make a real vector that contains the absolute values of all elements in the vector.

Returns:
A vector

conj

public void conj()
Change the vector to its conjugates.


scale

public void scale(double s)
Scale the vector with a factor s.

Parameters:
s - A double value

roundUp

public void roundUp(int n)
Round up this complex vector with n decimal format.

Parameters:
n - The number of decimal digits

roundUp

public static complexVector roundUp(complexVector x,
                                    int n)
RoundUp a complex vector x to another vector whose elements have n decimal digits

Parameters:
x - A complex vector
n - The number of decimal digits
Returns:
A complex vector

resize

public void resize(int n)
Change the size of the vector to n.

Parameters:
n - The new length of the vector

trimToSize

public void trimToSize()
Remove all the unused elements of the vector.


toString

public java.lang.String toString()
create a String that contains the elements of the vector with n decimal digits format.

Overrides:
toString in class java.lang.Object
Returns:
A String

toString

public java.lang.String toString(int n)
create a String that contains the elements of the vector with n decimal digits format.

Parameters:
n - The number of decimal digits
Returns:
A String

write

public void write(java.lang.String fileName)
Write all elements of the vector to a file.

Parameters:
fileName - A String

write

public void write(java.lang.String fileName,
                  int n)
Write all elements of the vector to a file with the n deimal digits format.

Parameters:
fileName - A String
n - The number of decimal digits

read

public void read(java.lang.String fileName)
Read data from a file to a complex vector.

Parameters:
fileName - a String

load

public void load(java.lang.String fileName)
Load data from a file to a complex vector.

Parameters:
fileName - a String

print

public void print()
Print all elements of the complex vector using System.out.


print

public void print(int n)
print all elements of the complex vector with n decimal digits using System.out.

Parameters:
n - The number of decimal digits