Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes

jscicalc.complex.Complex Class Reference

Complex numbers. More...

Collaboration diagram for jscicalc.complex.Complex:
Collaboration graph
[legend]

List of all members.

Classes

class  HTMLStringResult
 internal class used for result of tryHTMLString More...

Public Member Functions

 Complex ()
 Default constructor.
 Complex (double real)
 Constructor.
 Complex (double real, double imaginary)
 Constructor.
boolean isZero ()
 Test for equality to zero.
Long isInteger ()
 Test if an integer.
boolean isNegative ()
 Indicate whether or not Complex has leading negative sign.
double real ()
 Get the real part of the complex number.
double imaginary ()
 Get the real part of the complex number.
Complex conjugate ()
 Get the conjugate of this.
Complex negate ()
 Get the negative of this.
double abs ()
 Get the absolute value of this.
double arg ()
 Get the argument of this.
Complex inverse ()
 Get the inverse of this.
Complex imultiply ()
 Multiply this by i.
Complex scale (double real)
 Scale this.
Complex add (Complex complex)
 Add a complex number to this.
Complex subtract (Complex complex)
 Subtract a complex number from this.
Complex multiply (Complex complex)
 Multiply this by a complex number.
Complex divide (Complex complex)
 Divide this by a complex number.
Complex square ()
 Get the square of this.
Complex cube ()
 Get the cube of this.
Complex sqrt ()
 Get the square root of this.
Complex exp ()
 Find exp( this ).
Complex tenx ()
 Find 10 to the power of this.
Complex pow (Complex r)
 Find this to the power of r.
Complex root (Complex r)
 Find rth root of this.
Complex log ()
 Find log( this ).
Complex log10 ()
 Find log10( this ).
Complex cuberoot ()
 Get the cube root of this.
Complex sin ()
 Get the sine of this.
Complex cos ()
 Get the cosine of this.
Complex tan ()
 Get the tangent of this.
Complex asin ()
 Get the arcsine of this.
Complex acos ()
 Get the arccosine of this.
Complex atan ()
 Get the arctangent of this.
Complex and (Complex z)
 And with another complex.
Complex or (Complex z)
 Or with another complex.
Complex xor (Complex z)
 Xor with another complex.
double xor (double x, double y)
 Calculates x XOR y.
Complex factorial ()
 Calculate factorial of this.
Complex combination (Complex z)
 Calculates the number of unordered ways to choose y objects from this.
Complex permutation (Complex z)
 Calculates the number of ordered ways to choose y objects from this.
jscicalc.StringArray toHTMLSubString (int maxChars, int precision, final Base base, final Notation notation, double polarFactor)
 Function to create an HTML string representation of the complex number.
jscicalc.StringArray toHTMLParenString (int maxChars, int precision, final Base base, final Notation notation, double polarFactor)
int compareTo (Complex complex)
 The comparison operator.

Static Public Member Functions

static Complex polar (double r, double theta)
 Constructor.
static double or (double x, double y)
 Calculates x OR y.
static void main (String args[])
 Test code.

Static Public Attributes

static final Complex I = new Complex( 0, 1 )
 i
static final double smallImaginary = 1e-10
 A calculation (e.g.

Private Member Functions

double logabs ()
 Find log |this|.
Complex pow (int r)
 Find power of this for nonnegative integral powers.
Complex root (int r)
 Find root of this for integer.
double acosh_real (double y)
 Used to compute arccosh where y greater than or equal to 1.
Complex asin_real (double a)
 Used to compute arcsin where imaginary part is zero.
Complex acos_real (double a)
 Used to compute arccos where imaginary part is zero.
HTMLStringResult tryHTMLString (final int maxChars, final int precision, final Base base, final Notation notation)
 Internal function to create an HTML string representation of the complex number.

Static Private Member Functions

static double and (double x, double y)
 Calculates x AND y.
static double factorial (long x)
 Calculate factorial of x.
static double combination (long x, long y)
 Calculates the number of unordered ways to choose y objects from x.
static double permutation (long x, long y)
 Calculates the number of ordered ways to choose y objects from x.
static int min (int x, int y)
 Used by tryHTMLString.

Private Attributes

final double real_part
 The real part of the complex number.
final double imaginary_part
 The imaginary part of the complex number.

Static Private Attributes

static final Complex THIRD = new Complex( 1 / (double)3 )
 Used for cube roots.
static final Complex LOG10 = new Complex( StrictMath.log( 10 ) )
 Used for tenx.

Detailed Description

Complex numbers.

This is based on the GNU Scientific Library, http://gsl.gnu.org/, Copyright (C) 1996, 1997, 1998, 1999, 2000 Jorma Olavi Tätinen, Brian Gough and was suggested as an addition to the calculator by Sebastian Schneider ihi0 at sourceforge dot net.

Author:
J. D. Lamb
Version:
Revision:
1.16

Constructor & Destructor Documentation

jscicalc.complex.Complex.Complex (  ) 
jscicalc.complex.Complex.Complex ( double  real  ) 

Constructor.

Converts real number to complex representation.

Parameters:
real The number to be converted
jscicalc.complex.Complex.Complex ( double  real,
double  imaginary 
)

Constructor.

Converts real and imaginary parts to complex number.

Parameters:
real The real part
imaginary The imaginary part

References jscicalc.complex.Complex.imaginary_part, and jscicalc.complex.Complex.real_part.


Member Function Documentation

double jscicalc.complex.Complex.abs (  ) 
Complex jscicalc.complex.Complex.acos (  ) 
Complex jscicalc.complex.Complex.acos_real ( double  a  )  [private]

Used to compute arccos where imaginary part is zero.

Parameters:
a The real part
Returns:
the arc cos

References jscicalc.complex.Complex.acosh_real(), and jscicalc.complex.Complex.Complex().

Referenced by jscicalc.complex.Complex.acos().

double jscicalc.complex.Complex.acosh_real ( double  y  )  [private]

Used to compute arccosh where y greater than or equal to 1.

Parameters:
y The number
Returns:
the inverse hypebolic cosine

Referenced by jscicalc.complex.Complex.acos_real(), and jscicalc.complex.Complex.asin_real().

Complex jscicalc.complex.Complex.add ( Complex  complex  ) 
Complex jscicalc.complex.Complex.and ( Complex  z  ) 

And with another complex.

Parameters:
z The number to AND with this.
Returns:
The bitwise result of a logical and operation on this and z.

References jscicalc.complex.Complex.Complex(), jscicalc.complex.Complex.imaginary(), and jscicalc.complex.Complex.real().

static double jscicalc.complex.Complex.and ( double  x,
double  y 
) [static, private]

Calculates x AND y.

Used internally for and( z ).

Parameters:
x The first value (left of symbol)
y The second value (right of symbol)
Returns:
The result of the operation
double jscicalc.complex.Complex.arg (  ) 
Complex jscicalc.complex.Complex.asin (  ) 
Complex jscicalc.complex.Complex.asin_real ( double  a  )  [private]

Used to compute arcsin where imaginary part is zero.

Parameters:
a The real part
Returns:
the arc sin

References jscicalc.complex.Complex.acosh_real(), and jscicalc.complex.Complex.Complex().

Referenced by jscicalc.complex.Complex.asin().

Complex jscicalc.complex.Complex.atan (  ) 
Complex jscicalc.complex.Complex.combination ( Complex  z  ) 

Calculates the number of unordered ways to choose y objects from this.

Produces an error if this doesn’t make sense.

Parameters:
z The second value (right of symbol)
Returns:
The result of the operation

References jscicalc.complex.Complex.Complex(), jscicalc.complex.Complex.imaginary(), and jscicalc.complex.Complex.real().

Referenced by jscicalc.complex.Complex.combination().

static double jscicalc.complex.Complex.combination ( long  x,
long  y 
) [static, private]

Calculates the number of unordered ways to choose y objects from x.

Produces an error if this doesn’t make sense. Used internally.

Parameters:
x The first value (left of symbol)
y The second value (right of symbol)
Returns:
The result of the operation

References jscicalc.complex.Complex.combination().

int jscicalc.complex.Complex.compareTo ( Complex  complex  ) 

The comparison operator.

Parameters:
complex The Complex to be compared.
Returns:
integer indicating how expression is compared to this.

References jscicalc.complex.Complex.abs(), and jscicalc.complex.Complex.arg().

Referenced by jscicalc.expression.Sum.compareTo().

Complex jscicalc.complex.Complex.conjugate (  ) 

Get the conjugate of this.

Returns:
The conjugate of the complex number.

Reimplemented from jscicalc.OObject.

References jscicalc.complex.Complex.Complex(), jscicalc.complex.Complex.imaginary(), and jscicalc.complex.Complex.real().

Complex jscicalc.complex.Complex.cos (  ) 

Get the cosine of this.

Returns:
The cosine of this

References jscicalc.complex.Complex.Complex(), jscicalc.complex.Complex.imaginary(), and jscicalc.complex.Complex.real().

Referenced by jscicalc.pobject.Cos.function().

Complex jscicalc.complex.Complex.cube (  ) 

Get the cube of this.

Returns:
The cube of this

Reimplemented from jscicalc.OObject.

References jscicalc.complex.Complex.multiply(), and jscicalc.complex.Complex.square().

Complex jscicalc.complex.Complex.cuberoot (  ) 

Get the cube root of this.

Returns:
The cube root of this

Reimplemented from jscicalc.OObject.

References jscicalc.complex.Complex.root().

Complex jscicalc.complex.Complex.divide ( Complex  complex  ) 
Complex jscicalc.complex.Complex.exp (  ) 
Complex jscicalc.complex.Complex.factorial (  ) 

Calculate factorial of this.

Returns:
The factorial of this (or error if not a nonnegative integer).

Reimplemented from jscicalc.OObject.

References jscicalc.complex.Complex.Complex(), jscicalc.complex.Complex.imaginary(), and jscicalc.complex.Complex.real().

Referenced by jscicalc.complex.Complex.factorial().

static double jscicalc.complex.Complex.factorial ( long  x  )  [static, private]

Calculate factorial of x.

Used internally.

Parameters:
x The value (left of symbol)
Returns:
The result of the operation

References jscicalc.complex.Complex.factorial().

double jscicalc.complex.Complex.imaginary (  ) 

Get the real part of the complex number.

Returns:
The real part of the complex number.

References jscicalc.complex.Complex.imaginary_part.

Referenced by jscicalc.complex.Complex.abs(), jscicalc.complex.Complex.acos(), jscicalc.complex.Complex.add(), jscicalc.complex.Complex.and(), jscicalc.complex.Complex.arg(), jscicalc.complex.Complex.asin(), jscicalc.complex.Complex.atan(), jscicalc.complex.Test.checkNumber(), jscicalc.expression.Sum.clone(), jscicalc.expression.Product.clone(), jscicalc.complex.Complex.combination(), jscicalc.complex.Complex.conjugate(), jscicalc.complex.Complex.cos(), jscicalc.complex.Complex.divide(), jscicalc.complex.Complex.exp(), jscicalc.complex.Complex.factorial(), jscicalc.complex.Format.Format(), jscicalc.complex.Format.formatStandard(), jscicalc.pobject.Tan.function(), jscicalc.pobject.Sin.function(), jscicalc.graph.Locus.function(), jscicalc.pobject.Cos.function(), jscicalc.pobject.ATan.function(), jscicalc.pobject.ASin.function(), jscicalc.pobject.ACos.function(), jscicalc.Parser.getListAsStringVector(), jscicalc.complex.Complex.imultiply(), jscicalc.complex.Complex.inverse(), jscicalc.complex.Complex.isInteger(), jscicalc.complex.Complex.isNegative(), jscicalc.complex.Complex.isZero(), jscicalc.complex.Complex.logabs(), jscicalc.complex.Test.main(), jscicalc.complex.Complex.main(), jscicalc.complex.Complex.multiply(), jscicalc.complex.Complex.negate(), jscicalc.complex.Complex.or(), jscicalc.complex.Complex.permutation(), jscicalc.complex.Complex.pow(), jscicalc.complex.Complex.root(), jscicalc.complex.Complex.scale(), jscicalc.complex.Complex.sin(), jscicalc.complex.Complex.sqrt(), jscicalc.complex.Complex.subtract(), jscicalc.complex.Complex.tan(), jscicalc.complex.Complex.toHTMLParenString(), jscicalc.complex.Complex.toHTMLSubString(), jscicalc.complex.Complex.tryHTMLString(), and jscicalc.complex.Complex.xor().

Complex jscicalc.complex.Complex.imultiply (  ) 

Multiply this by i.

This function is used so that the calculator can enter complex numbers in convenient form without having to know when parsing a double that it will later be converted to a complex imaginary part.

Returns:
The complex number multiplied by i.

References jscicalc.complex.Complex.Complex(), jscicalc.complex.Complex.imaginary(), and jscicalc.complex.Complex.real().

Complex jscicalc.complex.Complex.inverse (  ) 
Long jscicalc.complex.Complex.isInteger (  ) 

Test if an integer.

Returns:
Long if it is, null if it is not an integer.

References jscicalc.complex.Complex.imaginary(), and jscicalc.complex.Complex.real().

Referenced by jscicalc.expression.Power.auto_simplify().

boolean jscicalc.complex.Complex.isNegative (  ) 
boolean jscicalc.complex.Complex.isZero (  ) 
Complex jscicalc.complex.Complex.log (  ) 

Find log( this ).

Returns:
log( this ).

Reimplemented from jscicalc.OObject.

References jscicalc.complex.Complex.arg(), jscicalc.complex.Complex.Complex(), and jscicalc.complex.Complex.logabs().

Referenced by jscicalc.complex.Complex.log10().

Complex jscicalc.complex.Complex.log10 (  ) 

Find log10( this ).

Returns:
log10( this ).

Reimplemented from jscicalc.OObject.

References jscicalc.complex.Complex.log(), and jscicalc.complex.Complex.scale().

double jscicalc.complex.Complex.logabs (  )  [private]
static void jscicalc.complex.Complex.main ( String  args[]  )  [static]
static int jscicalc.complex.Complex.min ( int  x,
int  y 
) [static, private]

Used by tryHTMLString.

Finds the smaller of x and y

Parameters:
x The first operand
y The second operand
Returns:
The smaller of x and y
Complex jscicalc.complex.Complex.multiply ( Complex  complex  ) 
Complex jscicalc.complex.Complex.negate (  ) 
Complex jscicalc.complex.Complex.or ( Complex  z  ) 

Or with another complex.

Parameters:
z The number to OR with this.
Returns:
The bitwise result of a logical or operation on this and z.

References jscicalc.complex.Complex.Complex(), jscicalc.complex.Complex.imaginary(), and jscicalc.complex.Complex.real().

static double jscicalc.complex.Complex.or ( double  x,
double  y 
) [static]

Calculates x OR y.

Used internally for and( z ).

Parameters:
x The first value (left of symbol)
y The second value (right of symbol)
Returns:
The result of the operation
static double jscicalc.complex.Complex.permutation ( long  x,
long  y 
) [static, private]

Calculates the number of ordered ways to choose y objects from x.

Produces an error if this doesn’t make sense. Used internally.

Parameters:
x The first value (left of symbol)
y The second value (right of symbol)
Returns:
The result of the operation

References jscicalc.complex.Complex.permutation().

Complex jscicalc.complex.Complex.permutation ( Complex  z  ) 

Calculates the number of ordered ways to choose y objects from this.

Produces an error if this doesn’t make sense.

Parameters:
z The second value (right of symbol)
Returns:
The result of the operation

References jscicalc.complex.Complex.Complex(), jscicalc.complex.Complex.imaginary(), and jscicalc.complex.Complex.real().

Referenced by jscicalc.complex.Complex.permutation().

static Complex jscicalc.complex.Complex.polar ( double  r,
double  theta 
) [static]

Constructor.

Converts real and imaginary parts to complex number. Probably not needed.

Parameters:
r The distance from zero
theta The angle

References jscicalc.complex.Complex.Complex().

Complex jscicalc.complex.Complex.pow ( int  r  )  [private]
Complex jscicalc.complex.Complex.pow ( Complex  r  ) 
double jscicalc.complex.Complex.real (  ) 

Get the real part of the complex number.

Returns:
The real part of the complex number.

References jscicalc.complex.Complex.real_part.

Referenced by jscicalc.complex.Complex.abs(), jscicalc.complex.Complex.acos(), jscicalc.complex.Complex.add(), jscicalc.complex.Complex.and(), jscicalc.complex.Complex.arg(), jscicalc.complex.Complex.asin(), jscicalc.complex.Complex.atan(), jscicalc.complex.Test.checkNumber(), jscicalc.expression.Sum.clone(), jscicalc.expression.Product.clone(), jscicalc.complex.Complex.combination(), jscicalc.complex.Complex.conjugate(), jscicalc.complex.Complex.cos(), jscicalc.complex.Complex.divide(), jscicalc.complex.Complex.exp(), jscicalc.complex.Complex.factorial(), jscicalc.complex.Format.Format(), jscicalc.complex.Format.formatStandard(), jscicalc.graph.Locus.function(), jscicalc.pobject.ASin.function(), jscicalc.pobject.ACos.function(), jscicalc.Parser.getListAsStringVector(), jscicalc.complex.Complex.imultiply(), jscicalc.complex.Complex.inverse(), jscicalc.complex.Complex.isInteger(), jscicalc.complex.Complex.isNegative(), jscicalc.complex.Complex.isZero(), jscicalc.complex.Complex.logabs(), jscicalc.complex.Test.main(), jscicalc.ParseBase.main(), jscicalc.complex.Complex.main(), jscicalc.complex.Complex.multiply(), jscicalc.complex.Complex.negate(), jscicalc.complex.Complex.or(), jscicalc.complex.Complex.permutation(), jscicalc.complex.Complex.pow(), jscicalc.complex.Complex.root(), jscicalc.complex.Complex.scale(), jscicalc.complex.Complex.sin(), jscicalc.complex.Complex.sqrt(), jscicalc.complex.Complex.subtract(), jscicalc.complex.Complex.tan(), jscicalc.complex.Complex.toHTMLParenString(), jscicalc.complex.Complex.toHTMLSubString(), jscicalc.complex.Complex.tryHTMLString(), and jscicalc.complex.Complex.xor().

Complex jscicalc.complex.Complex.root ( int  r  )  [private]
Complex jscicalc.complex.Complex.root ( Complex  r  ) 
Complex jscicalc.complex.Complex.scale ( double  real  ) 
Complex jscicalc.complex.Complex.sin (  ) 
Complex jscicalc.complex.Complex.sqrt (  ) 
Complex jscicalc.complex.Complex.square (  ) 

Get the square of this.

Returns:
The square of this

Reimplemented from jscicalc.OObject.

References jscicalc.complex.Complex.multiply().

Referenced by jscicalc.complex.Complex.cube(), jscicalc.complex.Complex.pow(), and jscicalc.CalculatorApplet.statSumSquares().

Complex jscicalc.complex.Complex.subtract ( Complex  complex  ) 
Complex jscicalc.complex.Complex.tan (  ) 

Get the tangent of this.

Returns:
The tangent of this

References jscicalc.complex.Complex.Complex(), jscicalc.complex.Complex.imaginary(), and jscicalc.complex.Complex.real().

Referenced by jscicalc.pobject.Tan.function().

Complex jscicalc.complex.Complex.tenx (  ) 

Find 10 to the power of this.

Returns:
10 to the power of this.

Reimplemented from jscicalc.OObject.

References jscicalc.complex.Complex.exp(), jscicalc.complex.Complex.LOG10, and jscicalc.complex.Complex.multiply().

jscicalc.StringArray jscicalc.complex.Complex.toHTMLParenString ( int  maxChars,
int  precision,
final Base  base,
final Notation  notation,
double  polarFactor 
)
jscicalc.StringArray jscicalc.complex.Complex.toHTMLSubString ( int  maxChars,
int  precision,
final Base  base,
final Notation  notation,
double  polarFactor 
)

Function to create an HTML string representation of the complex number.

This has six arguments. First, we need to know the maximum number of characters available and the desired precision of the complex numbers. These are given as two arguments. Then we need to know the base Then we need to know whether the Complex number is to be represented in standard or scientific notation. These give the last two arguments. Finally we need to know if we must use complex notation. If not we can ignore small imaginary parts (and zero real part).

Parameters:
maxChars The maximum number of (visible) characters we can use
precision The desired number of significant figures
base The required base
notation The notation to use to display this value
polarFactor Not used
Returns:
a vector of Strings of at most maxChars HTML characters representing the complex number

References jscicalc.Notation.complex(), jscicalc.complex.Complex.imaginary(), jscicalc.complex.Complex.real(), jscicalc.Notation.rectangular(), jscicalc.Notation.setComplex(), jscicalc.Notation.setNonComplex(), jscicalc.Notation.setPolar(), jscicalc.Notation.setRectangular(), jscicalc.Notation.setScientific(), jscicalc.Notation.setStandard(), jscicalc.Notation.standard(), jscicalc.StringArray.StringArray(), jscicalc.complex.Complex.HTMLStringResult.stringVector, and jscicalc.complex.Complex.tryHTMLString().

Referenced by jscicalc.expression.Sum.toHTMLSubString().

HTMLStringResult jscicalc.complex.Complex.tryHTMLString ( final int  maxChars,
final int  precision,
final Base  base,
final Notation  notation 
) [private]

Internal function to create an HTML string representation of the complex number.

This has five arguments. First, we need to know the maximum number of characters available and the desired precision of the complex numbers. These are given as two arguments. Then we need to know the base Then we need to know whether the Complex number is to be represented in standard or scientific notation. These give the last two arguments. Finally we need to know if we must use complex notation. If not we can ignore small imaginary parts (and zero real part). The fifth parameter is returned as TRUE or FALSE according as the representation would or would not need parentheses if expressed as part of a product.

Parameters:
maxChars The maximum number of (visible) characters we can use
precision The desired number of significant figures
base The required base
notation The notation to use to display this value
Returns:
a String of at most maxChars HTML characters representing the complex number

References jscicalc.complex.Complex.abs(), jscicalc.complex.Complex.arg(), jscicalc.Notation.complex(), jscicalc.complex.DoubleFormat.getAbsNumber(), jscicalc.complex.Complex.imaginary(), jscicalc.complex.DoubleFormat.NullRepresentation, jscicalc.complex.Complex.HTMLStringResult.parentheses, jscicalc.Notation.polar(), jscicalc.complex.Complex.real(), jscicalc.Notation.rectangular(), jscicalc.complex.DoubleFormat.representation(), jscicalc.Notation.scientific(), jscicalc.complex.DoubleFormat.setNotation(), jscicalc.complex.DoubleFormat.setPrecision(), jscicalc.Notation.setScientific(), jscicalc.complex.Complex.smallImaginary, jscicalc.StringArray.StringArray(), and jscicalc.complex.Complex.HTMLStringResult.stringVector.

Referenced by jscicalc.complex.Complex.toHTMLParenString(), and jscicalc.complex.Complex.toHTMLSubString().

double jscicalc.complex.Complex.xor ( double  x,
double  y 
)

Calculates x XOR y.

Used internally by xor().

Parameters:
x The first value (left of symbol)
y The second value (right of symbol)
Returns:
The result of the operation
Complex jscicalc.complex.Complex.xor ( Complex  z  ) 

Xor with another complex.

Parameters:
z The number to XOR with this.
Returns:
The bitwise result of a logical xor operation on this and z.

References jscicalc.complex.Complex.Complex(), jscicalc.complex.Complex.imaginary(), and jscicalc.complex.Complex.real().


Member Data Documentation

final Complex jscicalc.complex.Complex.I = new Complex( 0, 1 ) [static]

The imaginary part of the complex number.

Referenced by jscicalc.complex.Complex.Complex(), and jscicalc.complex.Complex.imaginary().

final Complex jscicalc.complex.Complex.LOG10 = new Complex( StrictMath.log( 10 ) ) [static, private]

Used for tenx.

Referenced by jscicalc.complex.Complex.tenx().

final double jscicalc.complex.Complex.real_part [private]

The real part of the complex number.

Referenced by jscicalc.complex.Complex.Complex(), and jscicalc.complex.Complex.real().

final double jscicalc.complex.Complex.smallImaginary = 1e-10 [static]

A calculation (e.g.

sin) might create a small imaginary part. If it is smaller than this number in size AND we want to ignore small complex parts, ignore it.

Referenced by jscicalc.complex.Complex.tryHTMLString().

final Complex jscicalc.complex.Complex.THIRD = new Complex( 1 / (double)3 ) [static, private]

Used for cube roots.


The documentation for this class was generated from the following file: