Class ImmutableComplex
- java.lang.Object
-
- com.singularsys.jep.standard.Complex
-
- com.singularsys.jep.standard.Complex.NonPropagatingImmutableComplex
-
- com.singularsys.jep.standard.ImmutableComplex
-
- All Implemented Interfaces:
java.io.Serializable
public class ImmutableComplex extends Complex.NonPropagatingImmutableComplex
An Immutable version of the Complex numbers. In this class the values of complex numbers can never be changed, further any operation likeconj()
oradd(Complex)
will also return an ImmutableComplex.- Since:
- Jep 4.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.singularsys.jep.standard.Complex
Complex.NonPropagatingImmutableComplex
-
-
Field Summary
Fields Modifier and Type Field Description static Complex
U_I
Unmodifiable constant 0+1 istatic Complex
U_MINUS_I
Unmodifiable constant 0-1 istatic Complex
U_MINUS_ONE
Unmodifiable constant -1+0 istatic Complex
U_ONE
Unmodifiable constant 1+0 istatic Complex
U_ZERO
Unmodifiable constant 0+0 i
-
Constructor Summary
Constructors Constructor Description ImmutableComplex()
ImmutableComplex(double x)
ImmutableComplex(double x, double y)
ImmutableComplex(Complex z)
ImmutableComplex(java.lang.Number x)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ImmutableComplex
acos()
Returns the arccos of this complex number.ImmutableComplex
acosh()
Returns the inverse hyperbolic cosine of this complex number.ImmutableComplex
add(Complex z)
Adds the complex number with another complex value.ImmutableComplex
asin()
Returns the arcsin of this complex number.ImmutableComplex
asinh()
Returns the inverse hyperbolic sine of this complex number.ImmutableComplex
atan()
Returns the arc tangent of this complex number.ImmutableComplex
atanh()
Returns the inverse hyperbolic tangent of this complex number.ImmutableComplex
conj()
Returns the complex conjugate.ImmutableComplex
cos()
Returns the cosine of this complex number.ImmutableComplex
cosh()
Returns the hyperbolic cosine of this complex number.ImmutableComplex
div(Complex z)
Returns the result of dividing this complex number by the parameter.ImmutableComplex
fastPower(int n)
Calculate integer powers by repeated multiplications.ImmutableComplex
log()
Returns the logarithm of this complex number.ImmutableComplex
mul(double b)
Multiply the complex number with a double value.ImmutableComplex
mul(Complex z)
Multiply the complex number with another complex value.ImmutableComplex
neg()
Returns the negative value of this complex number.static ImmutableComplex
polarValueOf(java.lang.Number r, java.lang.Number theta)
ImmutableComplex
power(double exponent)
Returns this complex number raised to a double argument.ImmutableComplex
power(int n)
Raise this complex to an integer power.ImmutableComplex
power(Complex exponent)
Returns the value of this complex number raised to the power of a complex exponent If the this is zero return this.ImmutableComplex
powerD(double exponent)
Returns the value of this complex number raised to the power of a real component (in double precision).ImmutableComplex
powerI(int n)
Raise a complex number to an integer power.ImmutableComplex
reciprocal()
Returns the reciprocal of a complex number 1/z.ImmutableComplex
sin()
Returns the sine of this complex number.ImmutableComplex
sinh()
Returns the hyperbolic sine of this complex number.ImmutableComplex
sqrt()
Calculates the square root of this object.ImmutableComplex
sub(Complex z)
Subtracts a complex number from thisImmutableComplex
tan()
Returns the tangent of this complex number.ImmutableComplex
tanh()
Returns the hyperbolic tangent of this complex number.-
Methods inherited from class com.singularsys.jep.standard.Complex.NonPropagatingImmutableComplex
set, set, setIm, setRe
-
-
-
-
Field Detail
-
U_ZERO
public static final Complex U_ZERO
Unmodifiable constant 0+0 i
-
U_ONE
public static final Complex U_ONE
Unmodifiable constant 1+0 i
-
U_MINUS_ONE
public static final Complex U_MINUS_ONE
Unmodifiable constant -1+0 i
-
U_I
public static final Complex U_I
Unmodifiable constant 0+1 i
-
U_MINUS_I
public static final Complex U_MINUS_I
Unmodifiable constant 0-1 i
-
-
Constructor Detail
-
ImmutableComplex
public ImmutableComplex()
-
ImmutableComplex
public ImmutableComplex(Complex z)
-
ImmutableComplex
public ImmutableComplex(double x, double y)
-
ImmutableComplex
public ImmutableComplex(double x)
-
ImmutableComplex
public ImmutableComplex(java.lang.Number x)
-
-
Method Detail
-
polarValueOf
public static ImmutableComplex polarValueOf(java.lang.Number r, java.lang.Number theta)
-
neg
public ImmutableComplex neg()
Description copied from class:Complex
Returns the negative value of this complex number.
-
mul
public ImmutableComplex mul(double b)
Description copied from class:Complex
Multiply the complex number with a double value.
-
add
public ImmutableComplex add(Complex z)
Description copied from class:Complex
Adds the complex number with another complex value.
-
sub
public ImmutableComplex sub(Complex z)
Description copied from class:Complex
Subtracts a complex number from this
-
mul
public ImmutableComplex mul(Complex z)
Description copied from class:Complex
Multiply the complex number with another complex value.
-
div
public ImmutableComplex div(Complex z)
Description copied from class:Complex
Returns the result of dividing this complex number by the parameter. Algorithm adapted from Numerical Recipes in C - The Art of Scientific Computing ISBN 0-521-43108-5
-
reciprocal
public ImmutableComplex reciprocal()
Description copied from class:Complex
Returns the reciprocal of a complex number 1/z. This was broken in version < 4.0.- Overrides:
reciprocal
in classComplex
- Returns:
- 1/(this)
-
power
public ImmutableComplex power(int n)
Description copied from class:Complex
Raise this complex to an integer power. For small power use theComplex.fastPower(int)
method which does repeated multiplication and is generally faster. For larger power useComplex.powerI(int)
which can be more accurate.
-
powerI
public ImmutableComplex powerI(int n)
Description copied from class:Complex
Raise a complex number to an integer power. Uses the polar form[r;th]^n -> [r^n;n th]
and the efficient power method fromPower.power(double, int)
Slower than
-
fastPower
public ImmutableComplex fastPower(int n)
Description copied from class:Complex
Calculate integer powers by repeated multiplications. Soz^5 = z*(z*z)*(z*z)
. This routine is generally faster but can accumulate errors for large exponents.
-
powerD
public ImmutableComplex powerD(double exponent)
Description copied from class:Complex
Returns the value of this complex number raised to the power of a real component (in double precision).This method considers special cases where a simpler algorithm would return "ugly" results.
For example when the expression (-1e40)^0.5 is evaluated without considering the special case, the argument of the base is the double number closest to pi. When sin and cos are used for the final evaluation of the result, the slight difference of the argument from pi causes a non-zero value for the real component of the result. Because the value of the base is so high, the error is magnified. Although the error is normal for floating point calculations, the consideration of commonly occurring special cases improves the accuracy and aesthetics of the results.If you know a more elegant way to solve this problem, please let me know at [email protected] .
Testing with roots of unity show errors are typically within 128 * ulp, so |actual-result|/|actual| < 1e-13.
-
power
public ImmutableComplex power(double exponent)
Description copied from class:Complex
Returns this complex number raised to a double argument. If the exponent is an integer returnsComplex.power(int)
otherwise callsComplex.powerD(double)
.
-
power
public ImmutableComplex power(Complex exponent)
Description copied from class:Complex
Returns the value of this complex number raised to the power of a complex exponent If the this is zero return this. If the exponent has zero imaginary part use
-
conj
public ImmutableComplex conj()
Description copied from class:Complex
Returns the complex conjugate.
-
log
public ImmutableComplex log()
Description copied from class:Complex
Returns the logarithm of this complex number. The real part is Math.log(this.abs()) and the complex part is this.arg(), in the range -pi .. pi.
-
sqrt
public ImmutableComplex sqrt()
Description copied from class:Complex
Calculates the square root of this object. Adapted from Numerical Recipes in C - The Art of Scientific Computing (ISBN 0-521-43108-5)
-
sin
public ImmutableComplex sin()
Description copied from class:Complex
Returns the sine of this complex number.
-
cos
public ImmutableComplex cos()
Description copied from class:Complex
Returns the cosine of this complex number.
-
tan
public ImmutableComplex tan()
Description copied from class:Complex
Returns the tangent of this complex number.
-
asin
public ImmutableComplex asin()
Description copied from class:Complex
Returns the arcsin of this complex number.
-
acos
public ImmutableComplex acos()
Description copied from class:Complex
Returns the arccos of this complex number.
-
atan
public ImmutableComplex atan()
Description copied from class:Complex
Returns the arc tangent of this complex number.
-
sinh
public ImmutableComplex sinh()
Description copied from class:Complex
Returns the hyperbolic sine of this complex number.
-
cosh
public ImmutableComplex cosh()
Description copied from class:Complex
Returns the hyperbolic cosine of this complex number.
-
tanh
public ImmutableComplex tanh()
Description copied from class:Complex
Returns the hyperbolic tangent of this complex number.
-
asinh
public ImmutableComplex asinh()
Description copied from class:Complex
Returns the inverse hyperbolic sine of this complex number.
-
acosh
public ImmutableComplex acosh()
Description copied from class:Complex
Returns the inverse hyperbolic cosine of this complex number.
-
atanh
public ImmutableComplex atanh()
Description copied from class:Complex
Returns the inverse hyperbolic tangent of this complex number.
-
-