complex v0.2.0 Complex
Complex is a library for types and mathematical functions for complex numbers.
Each complex number is represented as a structure holding the real and imaginary part. There are functions for creation and manipulation of them. Unfortunately since there is n operator overloading in Elixir the math functions (add, subtract, etc.) are implemented as add/2, sub/2, etc.
Examples
iex> Complex.new(3, 4)
%Complex{im: 4, re: 3}
iex> Complex.imag()
%Complex{im: 1.0, re: 0.0}
Summary
Functions
Returns a new complex that is the magnitude (length)) of the provided complex number
Returns a new complex that is the inverse cosine (i.e., arccosine) of the provided parameter
Returns a new complex that is the inverse hyperbolic cosine (i.e., arccosh) of the provided parameter
Returns a new complex that is the inverse cotangent (i.e., arccotangent) of the provided parameter
Returns a new complex that is the inverse hyperbolic cotangent (i.e., arccoth) of the provided parameter
Returns a new complex that is the inverse cosecant (i.e., arccosecant) of the provided parameter
Returns a new complex that is the inverse hyperbolic cosecant (i.e., arccsch) of the provided parameter
Returns a new complex that is the sum of the provided complex numbers
Returns a new complex that is the inverse secant (i.e., arcsecant) of the provided parameter
Returns a new complex that is the inverse hyperbolic secant (i.e., arcsech) of the provided parameter
Returns a new complex that is the inverse sine (i.e., arcsine) of the provided parameter
Returns a new complex that is the inverse hyperbolic sine (i.e., arcsinh) of the provided parameter
Returns a new complex that is the inverse tangent (i.e., arctangent) of the provided parameter
Returns a new complex that is the inverse hyperbolic tangent (i.e., arctanh) of the provided parameter
Returns a new complex that is the complex conjugate of the provided complex number
Returns a new complex that is the cosine of the provided parameter
Returns a new complex that is the hyperbolic cosine of the provided parameter
Returns a new complex that is the cotangent of the provided parameter
Returns a new complex that is the hyperbolic cotangent of the provided parameter
Returns a new complex that is the cosecant of the provided parameter
Returns a new complex that is the hyperbolic cosecant of the provided parameter
Returns a new complex that is the ratio (division) of the provided complex numbers
Returns a new complex that is the complex exponential of the provided complex number. That is, e raised to the power z
Returns a new complex number described by the supplied polar coordinates. That is, the complex (real and imaginary) will have radius (magnitude) r and angle (phase) phi
Returns the polar coordinates of the supplied complex. That is, the returned tuple {r,phi} is the magnitude and phase of z
Returns a new complex representing the pure imaginary number sqrt(-1)
Returns a new complex that is the complex natural log of the provided complex number. That is, log base e of z
Returns a new complex that is the complex log base 10 of the provided complex number
Returns a new complex that is the complex log base 2 of the provided complex number
Returns a new complex that is the product of the provided complex numbers
Returns a new complex that is the “negation” of the provided parameter. That is, the real and imaginary parts are negated
Returns a new complex with specified real and imaginary components. The imaginary part defaults to zero so a “real” number can be created with new/1
Returns the phase angle of the supplied complex
Returns a new complex that is the provided parameter a raised to the complex power b
Returns a new complex that is the secant of the provided parameter
Returns a new complex that is the hyperbolic secant of the provided parameter
Returns a new complex that is the sine of the provided parameter
Returns a new complex that is the hyperbolic sine of the provided parameter
Returns a new complex that is the complex square root of the provided complex number
Returns a new complex that is the difference of the provided complex numbers
Returns a new complex that is the tangent of the provided parameter
Returns a new complex that is the hyperbolic tangent of the provided parameter
Types
complex :: %Complex{re: number, im: number}
General type for complex numbers
Functions
Specs
abs(complex) :: number
Returns a new complex that is the magnitude (length)) of the provided complex number.
See also
Examples
iex> Complex.abs( Complex.fromPolar(1, :math.pi/2) )
1.0
Returns a new complex that is the inverse cosine (i.e., arccosine) of the provided parameter.
See also
Examples
iex> Complex.acos( Complex.fromPolar(2,:math.pi) )
%Complex{im: 1.3169578969248164, re: -3.141592653589793}
iex> Complex.cos( Complex.acos(Complex.new(2,3)) )
%Complex{im: 3.0, re: 2.0000000000000004}
Returns a new complex that is the inverse hyperbolic cosine (i.e., arccosh) of the provided parameter.
See also
Examples
iex> Complex.acosh( Complex.fromPolar(2,:math.pi) )
%Complex{im: -3.141592653589793, re: -1.3169578969248164}
iex> Complex.cosh( Complex.acosh(Complex.new(2,3)) )
%Complex{im: 3.0, re: 2.0}
Returns a new complex that is the inverse cotangent (i.e., arccotangent) of the provided parameter.
See also
Examples
iex> Complex.acot( Complex.fromPolar(2,:math.pi) )
%Complex{im: -9.71445146547012e-17, re: -0.46364760900080615}
iex> Complex.cot( Complex.acot(Complex.new(2,3)) )
%Complex{im: 2.9999999999999996, re: 1.9999999999999991}
Returns a new complex that is the inverse hyperbolic cotangent (i.e., arccoth) of the provided parameter.
See also
Examples
iex> Complex.acoth( Complex.fromPolar(2,:math.pi) )
%Complex{im: -8.164311994315688e-17, re: -0.5493061443340548}
iex> Complex.coth( Complex.acoth(Complex.new(2,3)) )
%Complex{im: 2.999999999999999, re: 2.0}
Returns a new complex that is the inverse cosecant (i.e., arccosecant) of the provided parameter.
See also
Examples
iex> Complex.acsc( Complex.fromPolar(2,:math.pi) )
%Complex{im: 0.0, re: -0.5235987755982988}
iex> Complex.csc( Complex.acsc(Complex.new(2,3)) )
%Complex{im: 2.9999999999999996, re: 1.9999999999999993}
Returns a new complex that is the inverse hyperbolic cosecant (i.e., arccsch) of the provided parameter.
See also
Examples
iex> Complex.acsch( Complex.fromPolar(2,:math.pi) )
%Complex{im: -5.4767869826420256e-17, re: -0.48121182505960336}
iex> Complex.csch( Complex.acsch(Complex.new(2,3)) )
%Complex{im: 3.0000000000000018, re: 1.9999999999999982}
Returns a new complex that is the sum of the provided complex numbers.
See also
Examples
iex> Complex.add( Complex.fromPolar(1, :math.pi/2), Complex.fromPolar(1, :math.pi/2) )
%Complex{im: 2.0, re: 1.2246467991473532e-16}
Returns a new complex that is the inverse secant (i.e., arcsecant) of the provided parameter.
See also
Examples
iex> Complex.asec( Complex.fromPolar(2,:math.pi) )
%Complex{im: 0.0, re: 2.0943951023931957}
iex> Complex.sec( Complex.asec(Complex.new(2,3)) )
%Complex{im: 2.9999999999999987, re: 1.9999999999999984}
Returns a new complex that is the inverse hyperbolic secant (i.e., arcsech) of the provided parameter.
See also
Examples
iex> Complex.asech( Complex.fromPolar(2,:math.pi) )
%Complex{im: -2.0943951023931953, re: 0.0}
iex> Complex.sech( Complex.asech(Complex.new(2,3)) )
%Complex{im: 2.999999999999999, re: 2.0}
Returns a new complex that is the inverse sine (i.e., arcsine) of the provided parameter.
See also
Examples
iex> Complex.asin( Complex.fromPolar(2,:math.pi) )
%Complex{im: 1.3169578969248164, re: -1.5707963267948963}
iex> Complex.sin( Complex.asin(Complex.new(2,3)) )
%Complex{im: 3.000000000000001, re: 1.9999999999999991}
Returns a new complex that is the inverse hyperbolic sine (i.e., arcsinh) of the provided parameter.
See also
Examples
iex> Complex.asinh( Complex.fromPolar(2,:math.pi) )
%Complex{im: 1.0953573965284052e-16, re: -1.4436354751788099}
iex> Complex.sinh( Complex.asinh(Complex.new(2,3)) )
%Complex{im: 3.0, re: 2.000000000000001}
Returns a new complex that is the inverse tangent (i.e., arctangent) of the provided parameter.
See also
Examples
iex> Complex.atan( Complex.fromPolar(2,:math.pi) )
%Complex{im: 0.0, re: -1.1071487177940904}
iex> Complex.tan( Complex.atan(Complex.new(2,3)) )
%Complex{im: 3.0, re: 2.0}
Returns a new complex that is the inverse hyperbolic tangent (i.e., arctanh) of the provided parameter.
See also
Examples
iex> Complex.atanh( Complex.fromPolar(2,:math.pi) )
%Complex{im: 1.5707963267948966, re: -0.5493061443340549}
iex> Complex.tanh( Complex.atanh(Complex.new(2,3)) )
%Complex{im: 2.999999999999999, re: 1.9999999999999987}
Returns a new complex that is the complex conjugate of the provided complex number.
See also
Examples
iex> Complex.conjugate( Complex.new(1,2) )
%Complex{im: -2, re: 1}
Returns a new complex that is the cosine of the provided parameter.
See also
Examples
iex> Complex.cos( Complex.fromPolar(2,:math.pi) )
%Complex{im: 2.2271363664699914e-16, re: -0.4161468365471424}
Returns a new complex that is the hyperbolic cosine of the provided parameter.
See also
Examples
iex> Complex.cosh( Complex.fromPolar(2,:math.pi) )
%Complex{im: -8.883245978848233e-16, re: 3.7621956910836314}
Returns a new complex that is the cotangent of the provided parameter.
See also
Examples
iex> Complex.cot( Complex.fromPolar(2,:math.pi) )
%Complex{im: -2.9622992129532336e-16, re: 0.45765755436028577}
Returns a new complex that is the hyperbolic cotangent of the provided parameter.
See also
Examples
iex> Complex.coth( Complex.fromPolar(2,:math.pi) )
%Complex{im: -1.8619978115303632e-17, re: -1.037314720727548}
Returns a new complex that is the cosecant of the provided parameter.
See also
Examples
iex> Complex.csc( Complex.fromPolar(2,:math.pi) )
%Complex{im: 1.2327514463765779e-16, re: -1.0997501702946164}
Returns a new complex that is the hyperbolic cosecant of the provided parameter.
See also
Examples
iex> Complex.csch( Complex.fromPolar(2,:math.pi) )
%Complex{im: -7.00520014334671e-17, re: -0.2757205647717832}
Returns a new complex that is the ratio (division) of the provided complex numbers.
See also
Examples
iex> Complex.div( Complex.fromPolar(1, :math.pi/2), Complex.fromPolar(1, :math.pi/2) )
%Complex{im: 0.0, re: 1.0}
Returns a new complex that is the complex exponential of the provided complex number. That is, e raised to the power z.
See also
Examples
iex> Complex.exp( Complex.fromPolar(2,:math.pi) )
%Complex{im: 3.3147584285483636e-17, re: 0.1353352832366127}
Specs
fromPolar(number, number) :: complex
Returns a new complex number described by the supplied polar coordinates. That is, the complex (real and imaginary) will have radius (magnitude) r and angle (phase) phi.
See also
Examples
iex> Complex.fromPolar(1, :math.pi/2)
%Complex{im: 1.0, re: 6.123233995736766e-17}
Specs
getPolar(complex) :: {float, float}
Returns the polar coordinates of the supplied complex. That is, the returned tuple {r,phi} is the magnitude and phase of z.
See also
Examples
iex> Complex.getPolar( Complex.fromPolar(1,:math.pi/2) )
{1.0, 1.5707963267948966}
Specs
imag :: complex
Returns a new complex representing the pure imaginary number sqrt(-1).
See also
Examples
iex> Complex.imag()
%Complex{im: 1.0, re: 0.0}
Returns a new complex that is the complex natural log of the provided complex number. That is, log base e of z.
See also
Examples
iex> Complex.ln( Complex.fromPolar(2,:math.pi) )
%Complex{im: 3.141592653589793, re: 0.6931471805599453}
Returns a new complex that is the complex log base 10 of the provided complex number.
See also
Examples
iex> Complex.log10( Complex.fromPolar(2,:math.pi) )
%Complex{im: 1.3643763538418412, re: 0.30102999566398114}
Returns a new complex that is the complex log base 2 of the provided complex number.
See also
Examples
iex> Complex.log2( Complex.fromPolar(2,:math.pi) )
%Complex{im: 4.532360141827194, re: 1.0}
Returns a new complex that is the product of the provided complex numbers.
See also
Examples
iex> Complex.mult( Complex.fromPolar(1, :math.pi/2), Complex.fromPolar(1, :math.pi/2) )
%Complex{im: 1.2246467991473532e-16, re: -1.0}
iex> Complex.mult( Complex.imag(), Complex.imag() )
%Complex{im: 0.0, re: -1.0}
Returns a new complex that is the “negation” of the provided parameter. That is, the real and imaginary parts are negated.
See also
Examples
iex> Complex.neg( Complex.new(3,5) )
%Complex{im: -5, re: -3}
Specs
new(number, number) :: complex
Returns a new complex with specified real and imaginary components. The imaginary part defaults to zero so a “real” number can be created with new/1
See also
Examples
iex> Complex.new(3, 4)
%Complex{im: 4, re: 3}
iex> Complex.new(2)
%Complex{im: 0, re: 2}
Specs
phase(complex) :: float
Returns the phase angle of the supplied complex.
See also
Examples
iex> Complex.phase( Complex.fromPolar(1,:math.pi/2) )
1.5707963267948966
Returns a new complex that is the provided parameter a raised to the complex power b.
See also
Examples
iex> Complex.pow( Complex.fromPolar(2,:math.pi), Complex.imag() )
%Complex{im: 0.027612020368333014, re: 0.03324182700885666}
Returns a new complex that is the secant of the provided parameter.
See also
Examples
iex> Complex.sec( Complex.fromPolar(2,:math.pi) )
%Complex{im: -1.2860374461837126e-15, re: -2.402997961722381}
Returns a new complex that is the hyperbolic secant of the provided parameter.
See also
Examples
iex> Complex.sech( Complex.fromPolar(2,:math.pi) )
%Complex{im: 6.27608655779184e-17, re: 0.2658022288340797}
Returns a new complex that is the sine of the provided parameter.
See also
Examples
iex> Complex.sin( Complex.fromPolar(2,:math.pi) )
%Complex{im: -1.0192657827055095e-16, re: -0.9092974268256817}
Returns a new complex that is the hyperbolic sine of the provided parameter.
See also
Examples
iex> Complex.sinh( Complex.fromPolar(2,:math.pi) )
%Complex{im: 9.214721821703068e-16, re: -3.626860407847019}
Returns a new complex that is the complex square root of the provided complex number.
See also
Examples
iex> Complex.sqrt( Complex.fromPolar(2,:math.pi) )
%Complex{im: 1.4142135623730951, re: 8.659560562354933e-17}
Returns a new complex that is the difference of the provided complex numbers.
See also
Examples
iex> Complex.sub( Complex.fromPolar(1, :math.pi/2), Complex.fromPolar(1, :math.pi/2) )
%Complex{im: 0.0, re: 0.0}
Returns a new complex that is the tangent of the provided parameter.
See also
Examples
iex> Complex.tan( Complex.fromPolar(2,:math.pi) )
%Complex{im: 1.4143199004457917e-15, re: 2.185039863261519}