Skip to main content

Complex Number

Definition​

The Complex Number Algorithm is designed to perform arithmetic operations (addition, subtraction, multiplication, division) on complex numbers. Complex numbers consist of a real part and an imaginary part and are represented in the form a + bi, where 'a' is the real part, 'b' is the imaginary part, and 'i' is the imaginary unit (√-1)

Practice​

addComplex(a, b):
return (a.real + b.real, a.imag + b.imag)

subtractComplex(a, b):
return (a.real - b.real, a.imag - b.imag)

multiplyComplex(a, b):
real = (a.real * b.real) - (a.imag * b.imag)
imag = (a.real * b.imag) + (a.imag * b.real)
return (real, imag)

divideComplex(a, b):
conjugate_b = (b.real, -b.imag)
numerator = multiplyComplex(a, conjugate_b)
denominator = multiplyComplex(b, conjugate_b)
return (numerator.real / denominator.real, numerator.imag / denominator.real)