Class ComplexUtils
- java.lang.Object
-
- org.matheclipse.core.expression.ComplexUtils
-
public class ComplexUtils extends java.lang.ObjectStatic implementations of commonComplex-valued functions. Included are trigonometric, exponential, log, power and square root functions.Reference:
See individual method javadocs for the computational formulas used. In general, NaN values in either real or imaginary parts of input arguments result inComplexNum.NaNreturned. Otherwise, infinite or NaN values are returned as they arise in computing the real functions specified in the computational formulas. Null arguments result in NullPointerExceptions.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static ComplexNumacos(ComplexNum z)Compute the inverse cosine for the given complex argument.static ComplexNumasin(ComplexNum z)Compute the inverse sine for the given complex argument.static ComplexNumatan(ComplexNum z)Compute the inverse tangent for the given complex argument.static ComplexNumcos(ComplexNum z)Compute the cosine for the given complex argument.static ComplexNumcosh(ComplexNum z)Compute the hyperbolic cosine for the given complex argument.static ComplexNumexp(ComplexNum z)Compute the exponential function for the given complex argument.static ComplexNumlog(ComplexNum z)Compute the natural logarithm for the given complex argument.static ComplexNumpolar2Complex(double r, double theta)Creates a complex number from the given polar representation.static ComplexNumpow(ComplexNum y, ComplexNum x)Returns of value ofyraised to the power ofx.static ComplexNumsin(ComplexNum z)Compute the sine for the given complex argument.static ComplexNumsinh(ComplexNum z)Compute the hyperbolic sine for the given complex argument.static ComplexNumsqrt(ComplexNum z)Compute the square root for the given complex argument.static ComplexNumsqrt1z(ComplexNum z)Compute the square root of 1 -z2 for the given complex argument.static ComplexNumtan(ComplexNum z)Compute the tangent for the given complex argument.static ComplexNumtanh(ComplexNum z)Compute the hyperbolic tangent for the given complex argument.
-
-
-
Method Detail
-
acos
public static ComplexNum acos(ComplexNum z)
Compute the inverse cosine for the given complex argument.Implements the formula:
acos(z) = -i (log(z + i (sqrt(1 - z2))))Returns
ComplexNum.NaNif either real or imaginary part of the input argument isNaNor infinite.- Parameters:
z- the value whose inverse cosine is to be returned- Returns:
- the inverse cosine of
z - Throws:
java.lang.NullPointerException- ifzis null
-
asin
public static ComplexNum asin(ComplexNum z)
Compute the inverse sine for the given complex argument.Implements the formula:
asin(z) = -i (log(sqrt(1 - z2) + iz))Returns
ComplexNum.NaNif either real or imaginary part of the input argument isNaNor infinite.- Parameters:
z- the value whose inverse sine is to be returned.- Returns:
- the inverse sine of
z. - Throws:
java.lang.NullPointerException- ifzis null
-
atan
public static ComplexNum atan(ComplexNum z)
Compute the inverse tangent for the given complex argument.Implements the formula:
atan(z) = (i/2) log((i + z)/(i - z))Returns
ComplexNum.NaNif either real or imaginary part of the input argument isNaNor infinite.- Parameters:
z- the value whose inverse tangent is to be returned- Returns:
- the inverse tangent of
z - Throws:
java.lang.NullPointerException- ifzis null
-
cos
public static ComplexNum cos(ComplexNum z)
Compute the cosine for the given complex argument.Implements the formula:
where the (real) functions on the right-hand side arecos(a + bi) = cos(a)cosh(b) - sin(a)sinh(b)iMath.sin(double),Math.cos(double),MathUtils.cosh(double)andMathUtils.sinh(double).Returns
ComplexNum.NaNif either real or imaginary part of the input argument isNaN.Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.
Examples:
cos(1 ± INFINITY i) = 1 ∓ INFINITY i cos(±INFINITY + i) = NaN + NaN i cos(±INFINITY ± INFINITY i) = NaN + NaN i- Parameters:
z- the value whose cosine is to be returned- Returns:
- the cosine of
z - Throws:
java.lang.NullPointerException- ifzis null
-
cosh
public static ComplexNum cosh(ComplexNum z)
Compute the hyperbolic cosine for the given complex argument.Implements the formula:
where the (real) functions on the right-hand side arecosh(a + bi) = cosh(a)cos(b) + sinh(a)sin(b)iMath.sin(double),Math.cos(double),MathUtils.cosh(double)andMathUtils.sinh(double).Returns
ComplexNum.NaNif either real or imaginary part of the input argument isNaN.Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.
Examples:
cosh(1 ± INFINITY i) = NaN + NaN i cosh(±INFINITY + i) = INFINITY ± INFINITY i cosh(±INFINITY ± INFINITY i) = NaN + NaN iThrows
NullPointerExceptionif z is null.- Parameters:
z- the value whose hyperbolic cosine is to be returned.- Returns:
- the hyperbolic cosine of
z.
-
exp
public static ComplexNum exp(ComplexNum z)
Compute the exponential function for the given complex argument.Implements the formula:
where the (real) functions on the right-hand side areexp(a + bi) = exp(a)cos(b) + exp(a)sin(b)iMath.exp(double),Math.cos(double), andMath.sin(double).Returns
ComplexNum.NaNif either real or imaginary part of the input argument isNaN.Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.
Examples:
exp(1 ± INFINITY i) = NaN + NaN i exp(INFINITY + i) = INFINITY + INFINITY i exp(-INFINITY + i) = 0 + 0i exp(±INFINITY ± INFINITY i) = NaN + NaN iThrows
NullPointerExceptionif z is null.- Parameters:
z- the value- Returns:
- e
z
-
log
public static ComplexNum log(ComplexNum z)
Compute the natural logarithm for the given complex argument.Implements the formula:
where ln on the right hand side islog(a + bi) = ln(|a + bi|) + arg(a + bi)iMath.log(double),|a + bi|is the modulus,ExprImpl.abs(), andarg(a + bi) =Math.atan2(double, double)(b, a)Returns
ComplexNum.NaNif either real or imaginary part of the input argument isNaN.Infinite (or critical) values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.
Examples:
Throwslog(1 ± INFINITY i) = INFINITY ± (π/2)i log(INFINITY + i) = INFINITY + 0i log(-INFINITY + i) = INFINITY + πi log(INFINITY ± INFINITY i) = INFINITY ± (π/4)i log(-INFINITY ± INFINITY i) = INFINITY ± (3π/4)i log(0 + 0i) = -INFINITY + 0iNullPointerExceptionif z is null.- Parameters:
z- the value.- Returns:
- ln
z.
-
polar2Complex
public static ComplexNum polar2Complex(double r, double theta)
Creates a complex number from the given polar representation.The value returned is
r·ei·theta, computed asr·cos(theta) + r·sin(theta)iIf either
rorthetais NaN, orthetais infinite,ComplexNum.NaNis returned.If
ris infinite andthetais finite, infinite or NaN values may be returned in parts of the result, following the rules for double arithmetic.Examples:
polar2Complex(INFINITY, π/4) = INFINITY + INFINITY i polar2Complex(INFINITY, 0) = INFINITY + NaN i polar2Complex(INFINITY, -π/4) = INFINITY - INFINITY i polar2Complex(INFINITY, 5π/4) = -INFINITY - INFINITY i- Parameters:
r- the modulus of the complex number to createtheta- the argument of the complex number to create- Returns:
r·ei·theta- Throws:
java.lang.IllegalArgumentException- if r is negative- Since:
- 1.1
-
pow
public static ComplexNum pow(ComplexNum y, ComplexNum x)
Returns of value ofyraised to the power ofx.Implements the formula:
whereyx = exp(x·log(y))expandlogareexp(org.matheclipse.core.expression.ComplexNum)andlog(org.matheclipse.core.expression.ComplexNum), respectively.Returns
ComplexNum.NaNif either real or imaginary part of the input argument isNaNor infinite, or ifyequalsComplexNum.ZERO.- Parameters:
y- the base.x- the exponent.- Returns:
yx- Throws:
java.lang.NullPointerException- if either x or y is null
-
sin
public static ComplexNum sin(ComplexNum z)
Compute the sine for the given complex argument.Implements the formula:
where the (real) functions on the right-hand side aresin(a + bi) = sin(a)cosh(b) - cos(a)sinh(b)iMath.sin(double),Math.cos(double),MathUtils.cosh(double)andMathUtils.sinh(double).Returns
ComplexNum.NaNif either real or imaginary part of the input argument isNaN.Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.
Examples:
Throwssin(1 ± INFINITY i) = 1 ± INFINITY i sin(±INFINITY + i) = NaN + NaN i sin(±INFINITY ± INFINITY i) = NaN + NaN iNullPointerExceptionif z is null.- Parameters:
z- the value whose sine is to be returned.- Returns:
- the sine of
z.
-
sinh
public static ComplexNum sinh(ComplexNum z)
Compute the hyperbolic sine for the given complex argument.Implements the formula:
where the (real) functions on the right-hand side aresinh(a + bi) = sinh(a)cos(b)) + cosh(a)sin(b)iMath.sin(double),Math.cos(double),MathUtils.cosh(double)andMathUtils.sinh(double).Returns
ComplexNum.NaNif either real or imaginary part of the input argument isNaN.Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.
Examples:
sinh(1 ± INFINITY i) = NaN + NaN i sinh(±INFINITY + i) = ± INFINITY + INFINITY i sinh(±INFINITY ± INFINITY i) = NaN + NaN i- Parameters:
z- the value whose hyperbolic sine is to be returned- Returns:
- the hyperbolic sine of
z - Throws:
java.lang.NullPointerException- ifzis null
-
sqrt
public static ComplexNum sqrt(ComplexNum z)
Compute the square root for the given complex argument.Implements the following algorithm to compute
sqrt(a + bi):- Let
t = sqrt((|a| + |a + bi|) / 2) if
a ≥ 0returnt + (b/2t)ielse return|b|/2t + sign(b)t i
|a| =Math.abs(int)(a)|a + bi| =ExprImpl.abs()(a + bi)sign(b) =MathUtils.indicator(byte)(b)
Returns
ComplexNum.NaNif either real or imaginary part of the input argument isNaN.Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.
Examples:
sqrt(1 ± INFINITY i) = INFINITY + NaN i sqrt(INFINITY + i) = INFINITY + 0i sqrt(-INFINITY + i) = 0 + INFINITY i sqrt(INFINITY ± INFINITY i) = INFINITY + NaN i sqrt(-INFINITY ± INFINITY i) = NaN ± INFINITY i- Parameters:
z- the value whose square root is to be returned- Returns:
- the square root of
z - Throws:
java.lang.NullPointerException- ifzis null
- Let
-
sqrt1z
public static ComplexNum sqrt1z(ComplexNum z)
Compute the square root of 1 -z2 for the given complex argument.Computes the result directly as
sqrt(DoubleComplexImpl.ONE.subtract(z.multiply(z))).Returns
ComplexNum.NaNif either real or imaginary part of the input argument isNaN.Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.
- Parameters:
z- the value- Returns:
- the square root of 1 -
z2 - Throws:
java.lang.NullPointerException- ifzis null
-
tan
public static ComplexNum tan(ComplexNum z)
Compute the tangent for the given complex argument.Implements the formula:
where the (real) functions on the right-hand side aretan(a + bi) = sin(2a)/(cos(2a)+cosh(2b)) + [sinh(2b)/(cos(2a)+cosh(2b))]iMath.sin(double),Math.cos(double),MathUtils.cosh(double)andMathUtils.sinh(double).Returns
ComplexNum.NaNif either real or imaginary part of the input argument isNaN.Infinite (or critical) values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.
Examples:
tan(1 ± INFINITY i) = 0 + NaN i tan(±INFINITY + i) = NaN + NaN i tan(±INFINITY ± INFINITY i) = NaN + NaN i tan(±&pi/2 + 0 i) = ±INFINITY + NaN i- Parameters:
z- the value whose tangent is to be returned- Returns:
- the tangent of
z - Throws:
java.lang.NullPointerException- ifzis null
-
tanh
public static ComplexNum tanh(ComplexNum z)
Compute the hyperbolic tangent for the given complex argument.Implements the formula:
where the (real) functions on the right-hand side aretan(a + bi) = sinh(2a)/(cosh(2a)+cos(2b)) + [sin(2b)/(cosh(2a)+cos(2b))]iMath.sin(double),Math.cos(double),MathUtils.cosh(double)andMathUtils.sinh(double).Returns
ComplexNum.NaNif either real or imaginary part of the input argument isNaN.Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.
Examples:
tanh(1 ± INFINITY i) = NaN + NaN i tanh(±INFINITY + i) = NaN + 0 i tanh(±INFINITY ± INFINITY i) = NaN + NaN i tanh(0 + (&pi/2)i) = NaN + INFINITY i- Parameters:
z- the value whose hyperbolic tangent is to be returned- Returns:
- the hyperbolic tangent of
z - Throws:
java.lang.NullPointerException- ifzis null
-
-
DMelt 3.0 © DataMelt by jWork.ORG