package complex
This package is centered around the Complex class, with a focus on complex arithmetic.
The ComplexEvaluator object contains the evaluate(String)
method
for parsing a mathematical expression as a function of complex numbers.
- Source
- package.scala
val function = ComplexEvaluator.parse("log(i * x) - i * log(y)")
, val sine = Complex(3, 4).sin
- Alphabetic
- By Inheritance
- complex
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
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 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, andb
is called the imaginary part.- re
The real part
- im
The imaginary part
-
abstract
class
ComplexFunction
extends AnyRef
This represents a function of complex variables.
This represents a function of complex variables. It can be evaluated using a map of the variables and their values. The function will then be evaluated, substituting in each variable's respective value, returning a complex number as its output.
- See also
-
case class
VariableException
(message: String = null, cause: Throwable = null) extends Exception with Product with Serializable
An exception thrown by a ComplexFunction on evaluation if an undefined variable is encountered.
An exception thrown by a ComplexFunction on evaluation if an undefined variable is encountered.
- message
The detailed message
- cause
The cause
Value Members
-
object
Complex
extends Serializable
A companion object for the Complex class.
A companion object for the Complex class.
This contains constants and implicit conversions.
-
object
ComplexEvaluator
extends AbstractEvaluator[ComplexFunction]
An Evaluator which parses an expression as a ComplexFunction.
An Evaluator which parses an expression as a ComplexFunction.
This allows the basic operators
+
,-
,*
,/
and^
and the use of brackets.The following strings are treated as constants:
- i
- pi or π
- tau or τ
- e
Furthermore, the following functions are recognised:
- im
- re
- arg
- abs
- conj
- sqrt or √
- log or ln
- sin
- asin
- cos
- acos
- tan
- atan
- sinh
- asinh
- cosh
- acosh
- tanh
- atanh
There is currently no support for implicit multiplication without the
*
symbol, such as2i
.A string can be parsed like this:
val complexFunction = ComplexEvaluator.evaluate("2 + i * sin(x)")
That returned
ComplexFunction
can then be evaluated for a given input forx
with:val complexNumber = complexFunction(Map("x" -> xValue))
For example, replacing
xValue
withComplex.Pi
would produce a complex number roughly equal to 2. It is recommended to then round the result by calling.round
to round the number to an appropriate degree of accuracy. -
object
ComplexFunction
A companion object for the
ComplexFunction
trait.A companion object for the
ComplexFunction
trait.This contains all the subclasses of the sealed
ComplexFunction
class, and implicit conversions.
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.