← Library
Tier 1 · precalculus

Complex Mult

Multiply two complex numbers (a+bi)(c+di).

Files (1)
COMPLEX.py317 bytes
def p(s):print(s)
def o1():
 p("=COMP MULT=")
 a=float(input("a:"))
 b=float(input("b:"))
 c=float(input("c:"))
 d=float(input("d:"))
 r=a*c-b*d
 i=a*d+b*c
 p("r="+str(r))
 p("i="+str(i))
def menu():
 while True:
  p("=COMPLEX=")
  p("1:MULT")
  p("0:EXIT")
  c=input("?>")
  if c=="1":o1()
  elif c=="0":break
menu()
How to use it

Launch COMPLEX from prgm. From the main menu pick 1:MULT to multiply two complex numbers.

For (a+bi)(c+di) the program asks for four numbers in order:

  1. a: real part of the first number.
  2. b: imaginary part of the first number.
  3. c: real part of the second number.
  4. d: imaginary part of the second number.

Output is the real part (r=) and imaginary part (i=) of the product. Press 0 from the menu to exit.

Example problem

Compute (1 + i)(2 − i).

Here a=1, b=1, c=2, d=−1.

  1. Run COMPLEX, choose 1:MULT.
  2. a:1, b:1, c:2, d:-1.
  3. Output: r=3.0, i=1.0.

Result: 3 + i. Verify by FOIL: 1·2 + 1·(−i) + i·2 + i·(−i) = 2 − i + 2i − i² = 2 + i + 1 = 3 + i. ✓

TI-84 Plus CE — try before committingoff
TI-84 Plus CE



  (calculator off)

  Press ON to start.
Test cases (2)
IDInputsExpected contains
one-plus-i-times-two-minus-i1, 1, 1, 2, -1, 0r=3.0, i=1.0
i-times-i1, 0, 1, 0, 1, 0r=-1.0, i=0.0