case class Complex(re: Double, im: Double = 0) extends Product with Serializable
A class which represents a complex number, that is, a number in the form a + bi
,
where i is one of the two square roots of -1.
a
is called the real part, and b
is called the imaginary part.
- re
The real part
- im
The imaginary part
- Source
- Complex.scala
- Alphabetic
- By Inheritance
- Complex
- Serializable
- Serializable
- Product
- Equals
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
Complex(re: Double, im: Double = 0)
- re
The real part
- im
The imaginary part
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
*(that: Complex): Complex
Multiplies this complex number by another one and returns the result.
Multiplies this complex number by another one and returns the result.
This implements the formula:
(a + bi) * (c + di) = (ac - bd) + (ad + bc)
- that
The complex number to be multiplied with this one
- returns
this * that
-
def
+(that: Complex): Complex
Adds this complex number to another one and returns the result.
Adds this complex number to another one and returns the result.
This implements the formula:
(a + bi) + (c + di) = (a + c) + (b + d)i
- that
The complex number to be added to this one
- returns
this + that
-
def
-(that: Complex): Complex
Subtracts another complex number from this one and returns the result.
Subtracts another complex number from this one and returns the result.
This implements the formula:
(a + bi) - (c + di) = (a - c) + (b - d)i
- that
The complex number to be subtracted from this one
- returns
this - that
-
def
/(that: Complex): Complex
Divides this complex number by another one and returns the result.
Divides this complex number by another one and returns the result.
This implements the formula:
(a + bi) / (c + di) = (a + bi)(c - di) / (c^2 + d^2)
The divisor is then a real number, and thus it is easy to compute the result when the nominator is divided by it.
If the divisor is 0, the result will be NaN + NaNi.
- that
The complex number by which this one is to be divided
- returns
this / that
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
abs: Double
Calculates the absolute value of this complex number, also known as the modulus, and returns it.
Calculates the absolute value of this complex number, also known as the modulus, and returns it. The absolute is the distance between a point on the complex plane representing the number and the origin.
This implements the formula:
|a + bi| = √(a^2 + b^2)
where
|z|
denotes the absolute ofz
.If either the real part of the imaginary part, or both, are infinite, the result will be positive infinity.
- returns
The absolute
-
def
acos: Complex
Returns the principal inverse cosine of this number, that is, the number whose cosine this is.
Returns the principal inverse cosine of this number, that is, the number whose cosine this is.
This implements the formula:
acos(z) = 1/2 * π - asin(z)
- returns
cos
-1
(this)
-
def
acosh: Complex
Returns the principal inverse hyperbolic cosine of this number, that is, the number whose hyperbolic cosine this is.
Returns the principal inverse hyperbolic cosine of this number, that is, the number whose hyperbolic cosine this is.
This implements the formula:
acosh(z) = log(z + √(z + 1) * √(z - 1))
- returns
cosh
-1
(this)
-
def
arg: Double
Calculates the argument, that is, the angle between the positive real axis and the point representing this number on the complex plane.
Calculates the argument, that is, the angle between the positive real axis and the point representing this number on the complex plane. The result will be between
π
and-π
.NaN and infinite values are handled by
math.atan2(Double, Double)
.- returns
The argument
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
asin: Complex
Returns the principal inverse sine of this number, that is, the number whose sine this is.
Returns the principal inverse sine of this number, that is, the number whose sine this is.
This implements the formula:
asin(z) = -i * log(iz + √(1 - z^2))
- returns
sin
-1
(this)
-
def
asinh: Complex
Returns the principal inverse hyperbolic sine of this number, that is, the number whose hyperbolic sine this is.
Returns the principal inverse hyperbolic sine of this number, that is, the number whose hyperbolic sine this is.
This implements the formula:
asinh(z) = -i * asin(iz)
- returns
sinh
-1
(this)
-
def
atan: Complex
Returns the principal inverse tangent of this number, that is, the number whose tangent this is.
Returns the principal inverse tangent of this number, that is, the number whose tangent this is.
This implements the formula:
atan(z) = i(log(1 - iz) - log(1 + iz)) / 2
- returns
tan
-1
(this)
-
def
atanh: Complex
Returns the principal inverse hyperbolic tangent of this number, that is, the number whose hyperbolic tangent this is.
Returns the principal inverse hyperbolic tangent of this number, that is, the number whose hyperbolic tangent this is.
This implements the formula:
atanh(z) = -i * atan(iz)
- returns
tanh
-1
(this)
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
conj: Complex
Returns the complex conjugate of this number, that is, a complex number with the same real part but with the imaginary part negated.
Returns the complex conjugate of this number, that is, a complex number with the same real part but with the imaginary part negated.
The conjugate of
a + bi
, therefore, isa - bi
- returns
The complex conjugate
-
def
cos: Complex
Returns the cosine of this number.
Returns the cosine of this number.
This implements the formula:
cos(z) = (e^(iz) + e^(-iz)) / 2
- returns
cos(this)
-
def
cosh: Complex
Returns the hyperbolic cosine of this number.
Returns the hyperbolic cosine of this number.
This implements the formula:
cosh(z) = cos(iz)
- returns
cosh(this)
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
exp: Complex
Calculates
e
to the power of this complex number and returns the result.Calculates
e
to the power of this complex number and returns the result.This implements the formula:
e ^ (a + bi) = (e ^ a) * (cos(b) + i * sin(b)
- returns
e
this
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
hasNaNPart: Boolean
Whether either the real part or the imaginary part of this complex number is
NaN
.Whether either the real part or the imaginary part of this complex number is
NaN
.- returns
re.isNaN || im.isNaN
- val im: Double
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
log: Complex
Calculates the principle natural logarithm of this number.
Calculates the principle natural logarithm of this number. Although numbers have infinitely many logarithms, separated from each-other by
2πi
, this will only return the one with its imaginary part in the range[-π, π]
.If the input is 0, the result will be negative infinity.
- returns
logₑ(this)
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
def
pow(that: Complex): Complex
Raises this number to the power of another and returns the result.
Raises this number to the power of another and returns the result.
This implements the formula:
a ^ b = e ^ (b * logₑ(a))
When this number is 0, then:
- if the real part of the exponent is greater than 0, then the result will be 0
- otherwise, the result will be NaN.
Note that this is a multivalued function, so there would be multiple possible results in reality. This will return the principle value, as determined by the principle value of
logₑ(a)
.- that
The exponent
- returns
this
that
- val re: Double
-
def
round(implicit precision: Int = 8): Complex
Rounds this complex number to the given number of significant figures and returns the result.
Rounds this complex number to the given number of significant figures and returns the result.
- precision
The number of significant figures to round to
- returns
The rounded complex number
-
def
sin: Complex
Returns the sine of this number.
Returns the sine of this number.
This implements the formula:
sin(z) = i(e^(-iz) - e^(iz)) / 2
- returns
sin(this)
-
def
sinh: Complex
Returns the hyperbolic sine of this number.
Returns the hyperbolic sine of this number.
This implements the formula:
sinh(z) = -i * sin(iz)
- returns
sinh(this)
-
def
sqrt: Complex
Returns the square root of this number, as given by
pow(0.5)
.Returns the square root of this number, as given by
pow(0.5)
.Every number apart from 0 has two square roots. The other square root will be the negative of this one. The returned square root will be the one whose real part is positive.
- returns
√this
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
tan: Complex
Returns the tangent of this number.
Returns the tangent of this number.
This implements the formula:
tan(z) = i(1 - e^(2iz)) / (e^(2iz) + 1)
This will return NaN where the tan function is undefined, which is where:
e^(2iz) + 1 = 0
- returns
tan(this)
-
def
tanh: Complex
Returns the hyperbolic tangent of this number.
Returns the hyperbolic tangent of this number.
This implements the formula:
tanh(z) = -i * tan(iz)
- returns
tanh(this)
-
def
toString(): String
Returns a string representation of this complex number as it would be written mathematically.
Returns a string representation of this complex number as it would be written mathematically.
For example, the string representation of
Complex(1, -2)
is1 - 2i
, and the string representation ofComplex(0, -1)
is-i
.- returns
A string representation of this complex number
- Definition Classes
- Complex → AnyRef → Any
-
def
unary_-: Complex
Calculates and returns the negative of this complex number.
Calculates and returns the negative of this complex number.
This implements the formula:
-(a + bi) = -a - bi
- returns
-a - bi
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
def
~^(that: Complex): Complex
Raises this number to the power of another and returns the result.
Raises this number to the power of another and returns the result.
This implements the formula:
a ^ b = e ^ (b * logₑ(a))
When this number is 0, then:
- if the real part of the exponent is greater than 0, then the result will be 0
- otherwise, the result will be NaN.
Note that this is a multivalued function, so there would be multiple possible results in reality. This will return the principle value, as determined by the principle value of
logₑ(a)
.- that
The exponent
- returns
this
that
This is the documentation for the Evaluator project (see GitHub).
The main package net.totietje.evaluator. The net.totietje.complex package contains an example usage of this package, which may also be useful.