Complex | Science @ Science @ MentDB Weak

Complex numbers
• Complex numbers (Apache Commons Math).
• Format: 3+4i, 3-4i, -2.5i, i, 7, 1e-3+2e2i. Also accepted in input: the suffix j (3+4j) and the form (3,4).
• The angles are in radians. The rounding noise is removed: exp(i.pi) gives -1, not -1+1.2246467991473532E-16i.

complex abs <z>


Description

Get the modulus

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (5)
admin
complex abs "3+4i"
mentdb
5
Modulus of an impedance 30 + 40j ohm
admin
complex abs "30+40i"
mentdb
50
Pure imaginary
admin
complex abs "-5i"
mentdb
5
Real number
admin
complex abs "-7"
mentdb
7
Modulus of an impedance 100 + 31.4i ohm
admin
complex abs "100+31.4i"
mentdb
104.81393037187374

complex add <z> <z2>


Description

Add two complex numbers

Parameters

z: A complex number, ex: 3+4i - String - required
z2: A complex number - String - required

Examples (4)
admin
complex add "3+4i" "1-2i"
mentdb
4+2i
Impedances in series
admin
complex add "50" "0+31.4i"
mentdb
50+31.4i
Opposite numbers: 0
admin
complex add "2+3i" "-2-3i"
mentdb
0
Series impedances: R + jL w + 1/(jC w)
admin
complex add (complex add "50" "0+31.4i") (complex div 1 "0+0.0628i")
mentdb
50+15.476433121019106i

complex arg <z>


Description

Get the argument (radians, in ]-pi, pi])

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (6)
admin
complex arg "i"
mentdb
1.5707963267948966
Phase of -1: pi
admin
complex arg "-1"
mentdb
3.141592653589793
Phase of 1 - i
admin
complex arg "1-i"
mentdb
-0.7853981633974483
Positive real: 0
admin
complex arg "5"
mentdb
0
Phase of an impedance in degrees
admin
math rad_to_deg (complex arg "100+100i")
mentdb
45
Third quadrant
admin
complex arg "-1-i"
mentdb
-2.356194490192345

complex conj <z>


Description

Get the conjugate

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (4)
admin
complex conj "3+4i"
mentdb
3-4i
Conjugate of a pure imaginary
admin
complex conj "2i"
mentdb
-2i
Real number: unchanged
admin
complex conj "4"
mentdb
4
z conj(z) = |z|^2
admin
complex mul "3+4i" (complex conj "3+4i")
mentdb
25

complex div <z> <z2>


Description

Divide two complex numbers

Parameters

z: A complex number, ex: 3+4i - String - required
z2: A complex number - String - required

Examples (5)
admin
complex div "1+2i" "3+4i"
mentdb
0.44+0.08i
1/i = -i
admin
complex div "1" "i"
mentdb
-i
By a real number
admin
complex div "4+6i" 2
mentdb
2+3i
Parallel impedances: Z1 Z2 / (Z1 + Z2)
admin
complex div (complex mul "100" "0+50i") (complex add "100" "0+50i")
mentdb
20+40i
By 0: error
admin
complex div "1+i" 0
mentdb
Sorry, an error appears (division by zero).

complex from_polar <r> <theta>


Description

Build a complex number from its modulus and its argument (radians)

Parameters

r: The modulus - Number - required
theta: The argument (radians) - Number - required

Examples (5)
admin
complex from_polar 2 1.5707963267948966
mentdb
2i
Modulus 1, angle pi
admin
complex from_polar 1 3.141592653589793
mentdb
-1
Modulus 1, angle 0: 1
admin
complex from_polar 1 0
mentdb
1
Angle of 45 degrees
admin
complex from_polar 1.4142135623730951 (math deg_to_rad 45)
mentdb
1.0000000000000002+i
Back from to_polar
admin
complex from_polar 5 0.9272952180016122
mentdb
3.0000000000000004+3.9999999999999996i

complex im <z>


Description

Get the imaginary part

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (4)
admin
complex im "3-4i"
mentdb
-4
Imaginary part of a real number
admin
complex im "5"
mentdb
0
Pure imaginary
admin
complex im "2.5i"
mentdb
2.5
Imaginary part of a product
admin
complex im (complex mul "1+2i" "3+4i")
mentdb
10

complex mul <z> <z2>


Description

Multiply two complex numbers

Parameters

z: A complex number, ex: 3+4i - String - required
z2: A complex number - String - required

Examples (5)
admin
complex mul "1+2i" "3+4i"
mentdb
-5+10i
i * i = -1
admin
complex mul "i" "i"
mentdb
-1
Rotation by 90 degrees: multiply by i
admin
complex mul "3+4i" "i"
mentdb
-4+3i
By a real number
admin
complex mul "1-2i" 3
mentdb
3-6i
(1+i)^2 = 2i
admin
complex mul "1+i" "1+i"
mentdb
2i

complex pow <z> <w>


Description

Get z1^z2 (principal value). An integer exponent is computed by exact multiplications.

Parameters

z: A complex number, ex: 3+4i - String - required
w: The exponent (real or complex) - String - required

Examples (6)
admin
complex pow "1+i" 8
mentdb
16
i^i is a real number
admin
complex pow "i" "i"
mentdb
0.20787957635076193
Square root as a power
admin
complex pow "-4" 0.5
mentdb
2i
Square root as a power
admin
complex pow "3+4i" 0.5
mentdb
2+i
Negative power
admin
complex pow "1+i" -2
mentdb
-0.5i
De Moivre: (cos t + i sin t)^n
admin
complex pow (complex from_polar 1 0.5) 4
mentdb
-0.4161468365471423+0.9092974268256818i

complex re <z>


Description

Get the real part

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (4)
admin
complex re "3+4i"
mentdb
3
Real part
admin
complex re "-2.5+1i"
mentdb
-2.5
Pure imaginary: 0
admin
complex re "7i"
mentdb
0
Real part of exp(i pi/3)
admin
complex re (complex exp "1.0471975511965976i")
mentdb
0.5000000000000001

complex roots <z> <n>


Description

Get the n n-th roots (JSON array of strings), the principal root first

Parameters

z: A complex number, ex: 3+4i - String - required
n: The degree of the root (integer >= 1) - Number - required

Examples (6)
admin
complex roots "-8" 3
mentdb
["1+1.7320508075688772i","-2","1-1.7320508075688772i"]
admin
complex roots 1 4
mentdb
["1","i","-1","-i"]
The 4 fourth roots of 1
admin
complex roots "1" 4
mentdb
["1","i","-1","-i"]
Square roots of i
admin
complex roots "i" 2
mentdb
["0.7071067811865476+0.7071067811865475i","-0.7071067811865475-0.7071067811865476i"]
Cube roots of 1
admin
complex roots 1 3
mentdb
["1","-0.5+0.8660254037844387i","-0.5-0.8660254037844387i"]
Fifth roots of 32
admin
complex roots 32 5
mentdb
["2","0.6180339887498949+1.902113032590307i","-1.6180339887498947+1.1755705045849465i","-1.6180339887498947-1.1755705045849465i","0.6180339887498949-1.902113032590307i"]

complex sqrt <z>


Description

Get the principal square root

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (6)
admin
complex sqrt "3+4i"
mentdb
2+i
admin
complex sqrt -4
mentdb
2i
Square root of -1
admin
complex sqrt "-1"
mentdb
i
Square root of i
admin
complex sqrt "i"
mentdb
0.7071067811865476+0.7071067811865475i
Square root of a negative real number
admin
complex sqrt "-9"
mentdb
3i
Square root of a positive real number
admin
complex sqrt 16
mentdb
4

complex sub <z> <z2>


Description

Subtract two complex numbers

Parameters

z: A complex number, ex: 3+4i - String - required
z2: A complex number - String - required

Examples (4)
admin
complex sub "3+4i" "1-2i"
mentdb
2+6i
Difference
admin
complex sub "1" "i"
mentdb
1-i
Same numbers: 0
admin
complex sub "2+i" "2+i"
mentdb
0
Real minus complex
admin
complex sub 5 "2+3i"
mentdb
3-3i

complex to_polar <z>


Description

Get the polar form {"r": modulus, "theta": argument in radians}

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (4)
admin
complex to_polar "1+i"
mentdb
{"r": 1.4142135623730951, "theta": 0.7853981633974483}
Polar form of -2
admin
complex to_polar "-2"
mentdb
{"r": 2, "theta": 3.141592653589793}
Pure imaginary
admin
complex to_polar "2i"
mentdb
{"r": 2, "theta": 1.5707963267948966}
3+4i: modulus 5
admin
complex to_polar "3+4i"
mentdb
{"r": 5, "theta": 0.9272952180016122}

complex acos <z>


Description

Get the inverse cosine (principal value).
On the branch cuts, the convention is the one of Mathematica (asin 3 = pi/2 - 1.7627i).

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (4)
admin
complex acos 2
mentdb
1.3169578969248164i
Inside [-1, 1]: real
admin
complex acos 0.5
mentdb
1.0471975511965976
Complex argument
admin
complex acos "1+i"
mentdb
0.9045568943023813-1.0612750619050357i
Below -1
admin
complex acos -2
mentdb
3.141592653589793-1.3169578969248166i

complex asin <z>


Description

Get the inverse sine (principal value).
On the branch cuts, the convention is the one of Mathematica (asin 3 = pi/2 - 1.7627i).

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (4)
admin
complex asin 2
mentdb
1.5707963267948966-1.3169578969248166i
Inside [-1, 1]: real
admin
complex asin 0.5
mentdb
0.5235987755982989
Complex argument
admin
complex asin "1+i"
mentdb
0.6662394324925153+1.0612750619050355i
Pure imaginary
admin
complex asin "i"
mentdb
0.8813735870195428i

complex atan <z>


Description

Get the inverse tangent (principal value).
On the branch cuts, the convention is the one of Mathematica (asin 3 = pi/2 - 1.7627i).

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (3)
admin
complex atan "1+i"
mentdb
1.0172219678978514+0.4023594781085251i
Real argument
admin
complex atan 1
mentdb
0.7853981633974483
Pure imaginary inside the unit disc
admin
complex atan "0.5i"
mentdb
0.5493061443340549i

complex cos <z>


Description

Get the cosine.
On the branch cuts, the convention is the one of Mathematica (asin 3 = pi/2 - 1.7627i).

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (4)
admin
complex cos "1+i"
mentdb
0.8337300251311491-0.9888977057628651i
cos(i) = cosh(1)
admin
complex cos "i"
mentdb
1.5430806348152437
Real argument
admin
complex cos 0
mentdb
1
cos(i x) = cosh(x)
admin
complex cos "2i"
mentdb
3.7621956910836314

complex cosh <z>


Description

Get the hyperbolic cosine.
On the branch cuts, the convention is the one of Mathematica (asin 3 = pi/2 - 1.7627i).

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (4)
admin
complex cosh "i"
mentdb
0.5403023058681398
Real argument
admin
complex cosh 1
mentdb
1.5430806348152437
Complex argument
admin
complex cosh "1+i"
mentdb
0.8337300251311491+0.9888977057628651i
cosh(i pi) = -1
admin
complex cosh "3.141592653589793i"
mentdb
-1

complex exp <z>


Description

Get the exponential.
On the branch cuts, the convention is the one of Mathematica (asin 3 = pi/2 - 1.7627i).

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (5)
admin
complex exp "3.141592653589793i"
mentdb
-1
Euler: exp(i pi/2) = i
admin
complex exp "1.5707963267948966i"
mentdb
i
Real argument
admin
complex exp 1
mentdb
2.718281828459045
exp(1 + i pi) = -e
admin
complex exp "1+3.141592653589793i"
mentdb
-2.718281828459045
A sine of phase 60 degrees as a phasor
admin
complex exp "1.0471975511965976i"
mentdb
0.5000000000000001+0.8660254037844386i

complex log <z>


Description

Get the natural logarithm (principal value, argument in ]-pi, pi]).
On the branch cuts, the convention is the one of Mathematica (asin 3 = pi/2 - 1.7627i).

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (5)
admin
complex log -1
mentdb
3.141592653589793i
log(i) = i pi/2
admin
complex log "i"
mentdb
1.5707963267948966i
ln(1) = 0
admin
complex log 1
mentdb
0
Complex argument
admin
complex log "1+i"
mentdb
0.3465735902799727+0.7853981633974483i
ln(0): error
admin
complex log 0
mentdb
Sorry, an error appears (the logarithm of 0 is not defined).

complex sin <z>


Description

Get the sine.
On the branch cuts, the convention is the one of Mathematica (asin 3 = pi/2 - 1.7627i).

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (5)
admin
complex sin "i"
mentdb
1.1752011936438014i
sin of a real number
admin
complex sin "1.5707963267948966"
mentdb
1
Real argument
admin
complex sin 1
mentdb
0.8414709848078965
sin(i x) = i sinh(x)
admin
complex sin "2i"
mentdb
3.6268604078470186i
Complex argument
admin
complex sin "1+i"
mentdb
1.2984575814159773+0.6349639147847361i

complex sinh <z>


Description

Get the hyperbolic sine.
On the branch cuts, the convention is the one of Mathematica (asin 3 = pi/2 - 1.7627i).

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (3)
admin
complex sinh "1+i"
mentdb
0.6349639147847361+1.2984575814159773i
Real argument
admin
complex sinh 1
mentdb
1.1752011936438014
sinh(i x) = i sin(x)
admin
complex sinh "1.5707963267948966i"
mentdb
i

complex tan <z>


Description

Get the tangent.
On the branch cuts, the convention is the one of Mathematica (asin 3 = pi/2 - 1.7627i).

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (3)
admin
complex tan "1+i"
mentdb
0.27175258531951174+1.0839233273386946i
Real argument
admin
complex tan 0.7853981633974483
mentdb
1
Pure imaginary
admin
complex tan "i"
mentdb
0.7615941559557649i

complex tanh <z>


Description

Get the hyperbolic tangent.
On the branch cuts, the convention is the one of Mathematica (asin 3 = pi/2 - 1.7627i).

Parameters

z: A complex number, ex: 3+4i - String - required

Examples (3)
admin
complex tanh "1+i"
mentdb
1.0839233273386946+0.27175258531951174i
Real argument
admin
complex tanh 1
mentdb
0.7615941559557649
Pure imaginary
admin
complex tanh "i"
mentdb
1.557407724654902i
start: 2026-10-29end: 2026-10-29v_start: 421v_end: