Skip to content

Complex

Arthur Guiot edited this page Oct 7, 2018 · 6 revisions

Starting v1.2.0, TheoremJS now supports complex numbers. All the following methods are chainable (except toString and arg).

Create a complex number

Here is how to create a complex number in TheoremJS:

t.complex(0, 1) // i
t.i             // i
t.complex(1, 1) // 1 + i
t.complex(2)    // 2

abs

This will return the absolute value of a complex number.

t.complex(3, 4).abs() //= t.complex(5, 0)

arg

This will return the argument of a complex number

t.complex(1, 1).arg() //= pi / 4 => BigNumber

clone

It will clone the complex number.

t.complex(2, 3).clone() //= t.complex(2, 3)

conjugate

This will multiply the imaginary part by -1

t.complex(1, 1).conjugate() //= t.complex(1, -1)

div or dividedBy

This will divide a complex a by another complex b

const a = t.complex(2, 3)
const b = t.complex(3, -5)

a.div(b).toString() //= "-0.26470588235294117647 + 0.55882352941176470588i"

eq or equal

const a = t.complex(2, 3)
const b = t.complex(3, 3).minus(t.complex(1, 0)

a.eq(b) //= true

exp

This will return the exponential of a complex number. (You can also do it by using t.exp)

t.complex(2, 3).exp().toString() //= "-7.31511009490109891372481413925 + 1.04274365623590274091988122355i"

ln and log(base)

t.complex(2, 3).ln().toString() //= "1.28247380404213 + 0.982793723247329i"
t.complex(100, 0).log(10).toString() //= "1.99992155781462 + 0i"

You can also use t.ln and t.log

minus

t.complex(3, -4).minus(t.complex(2, 4)) //= t.complex(1, -8)

negated

This will multiply the complex number by t.complex(-1, -1)

t.complex(2, 3).negated() //= t.complex(-2, -3)

plus

t.complex(18, -12).plus(t.complex(-3, 2)) //= t.complex(15, -10)

pow

Will elevate any complex a to complex power b

const a = t.complex(3, 2)
const b = t.complex(4, -2)

a.pow(b).toString() //= "535.424019276695978424428817368 - 115.76768825678578727266368994i"

times or multipliedBy

t.complex(2, 3).times(t.complex(4, 5)) //= t.complex(-7, 22)

To String

t.complex(1, 1).toString() // "1 + 1i"
t.i.toString()             // "0 + 1i"
t.complex(2)               // "2 + 0i"