fastmath.complex

Complex numbers functions.

Complex number is represented as Vec2 type (from clojure2d.math.vector namespace).

To create complex number use complex, vec2 or ->Vec2.

Implementation checks for ##Inf, ##NaN and some of the function distinguish +0.0 and -0.0

-I

abs

(abs z)

Absolute value, magnitude

Examples

Abs

(abs (complex 1 -3))
;;=> 3.1622776601683795

acos

(acos z)

acos

Examples

acos(z)

(acos (complex 2 -1))
;;=> [0.5073563032171444 1.4693517443681854]

Plot of acos

acosh

(acosh z)

acosh

acot

(acot z)

acot

acoth

(acoth z)

acsc

(acsc z)

acsc

acsch

(acsch z)

add

(add z1 z2)

Sum of two complex numbers

Examples

Sum

(add I ONE)
;;=> [1.0 1.0]

arg

(arg z)

Argument (angle) of the complex number

Examples

Argument

(m/degrees (arg I-))
;;=> -90.0

asec

(asec z)

asec

asech

(asech z)

asin

(asin z)

asin

Examples

asin(z)

(asin (complex 2 -1))
;;=> [1.0634400235777521 -1.4693517443681854]

Plot of asin

asinh

(asinh z)

asinh

atan

(atan z)

atan

Examples

atan(z)

(atan (complex 2 -1))
;;=> [1.1780972450961724 -0.17328679513998632]

Plot of atan

atanh

(atanh z)

atanh

complex

(complex a b)(complex a)(complex)

Create complex number. Represented as Vec2.

Examples

New complex number.

(complex 2 -1)
;;=> [2.0 -1.0]

conjugate

(conjugate z)

Complex conjugate. \(\bar{z}\)

Examples

Conjugate

(conjugate I)
;;=> [0.0 -1.0]

cos

(cos z)

cos

Examples

cos(z)

(cos (complex 2 -1))
;;=> [-0.6421481247155197 1.0686074213827785]

Plot of cos

cosh

(cosh z)

cosh

Examples

cosh(z)

(cosh (complex 2 -1))
;;=> [2.0327230070196656 -3.0518977991517997]

Plot of cosh

cot

(cot z)

csc

coth

(coth z)

coth

csc

(csc z)

csc

Examples

csc(z)

(csc (complex 2 -1))
;;=> [0.6354937992538998 -0.22150093085050923]

Plot of csc

csch

(csch z)

csch

csgn

(csgn re im)(csgn z)

Complex sgn.

Returns 0 for 0+0i or calls m/sgn on real part otherwise.

delta-eq

(delta-eq q1 q2)(delta-eq q1 q2 accuracy)

Compare complex numbers with given accuracy (10e-6 by default)

div

(div z1 z2)

Divide two complex numbers.

Examples

Divide

(div (complex 1 2) (complex 3 4))
;;=> [0.44 0.08]

exp

(exp z)

exp

Examples

exp(z)

(exp (complex 2 -1))
;;=> [3.992324048441272 -6.217676312367968]

\(e^{i\pi}+1\)

(add (exp (complex 0 m/PI)) ONE)
;;=> [0.0 1.224646799076922E-16]

Plot of exp

flip

(flip z)

Exchange imaginary and real parts

I

I-

im

(im z)

Imaginary part

imaginary?

(imaginary? z)

Is z is a pure imaginary number?

inf?

(inf? z)

Is infinite?

log

(log z)

log, principal value

Examples

log(z)

(log (complex 2 -1))
;;=> [0.8047189562170501 -0.4636476090008061]

log(e)

(log (complex m/E 0))
;;=> [1.0 0.0]

Plot of log

logb

(logb z b)

log with base b

mult

(mult z1 z2)

Multiply two complex numbers.

Examples

Multiply

(mult (complex 1 2) (complex 3 4))
;;=> [-5.0 10.0]

mult-I

(mult-I z)

mult-I-

(mult-I- z)

nan?

(nan? z)

Is NaN?

neg

(neg z)

Negate complex number. \(-z\)

Examples

Negate.

(neg (complex 1 2))
;;=> [-1.0 -2.0]

norm

(norm z)

Norm (Guass) of the complex number, absolute value squared

ONE

pow

(pow z1 z2)

Power. \(z_1^{z_2}\)

Examples

\(\sqrt{2}\)

(pow TWO (complex 0.5 0.0))
;;=> [1.4142135623730951 0.0]

Complex power

(pow (complex 1 2) (complex 3 4))
;;=> [0.12900959407446694 0.03392409290517002]

re

(re z)

Real part

real?

(real? z)

Is z is a real number?

reciprocal

(reciprocal z)

\(\frac{1}{z}\)

Examples

Reciprocal of real

(reciprocal TWO)
;;=> [0.5 -0.0]

Reciprocal of complex

(reciprocal (complex 0 2))
;;=> [0.0 -0.5]

Plot of reciprocal

scale

(scale z v)

Multiply by real number

sec

(sec z)

sec

Examples

sec(z)

(sec (complex 2 -1))
;;=> [-0.4131493442669398 -0.687527438655479]

Plot of sec

sech

(sech z)

sech

sin

(sin z)

sin

Examples

sin(z)

(sin (complex 2 -1))
;;=> [1.403119250622041 0.4890562590412935]

Plot of sin

sinh

(sinh z)

sinh

Examples

sinh(z)

(sinh (complex 2 -1))
;;=> [1.9596010414216063 -3.1657785132161678]

Plot of sinh

sq

(sq z)

Square complex number. \(z^2\)

Examples

Square.

(sq (complex 1 2))
;;=> [-3.0 4.0]

\(i^2\)

(sq I)
;;=> [-1.0 0.0]

Plot of sq

sqrt

(sqrt z)

Sqrt of complex number. \(\sqrt{z}\)

Examples

Square root of real.

(sqrt (complex 2 0))
;;=> [1.4142135623730951 0.0]

Square root of complex.

(sqrt (complex 2 2))
;;=> [1.5537739740300376 0.6435942529055827]

Plot of sqrt

sqrt1z

(sqrt1z z)

\(\sqrt{1-z^2}\)

Examples

Example 1

(sqrt1z (complex 2 3))
;;=> [3.115799084103365 -1.9256697360916721]

Plot of sqrt1z

sub

(sub z1 z2)

Difference of two complex numbers

Examples

Subtract

(sub ONE I-)
;;=> [1.0 1.0]

tan

(tan z)

tan

Examples

tan(z)

(tan (complex 2 -1))
;;=> [-0.24345820118572514 -1.16673625724092]

Plot of tan

tanh

(tanh z)

tanh

Examples

tanh(z)

(tanh (complex 2 -1))
;;=> [1.0147936161466335 -0.033812826079896684]

Plot of tanh

TWO

ZERO

zero?

(zero? z)

Is zero?