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()Tier 1 · precalculus
Complex Mult
Multiply two complex numbers (a+bi)(c+di).
Files (1)
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:
a:real part of the first number.b:imaginary part of the first number.c:real part of the second number.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.
- Run
COMPLEX, choose1:MULT. a:→ 1,b:→ 1,c:→ 2,d:→ -1.- 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)
| ID | Inputs | Expected contains |
|---|---|---|
| one-plus-i-times-two-minus-i | 1, 1, 1, 2, -1, 0 | r=3.0, i=1.0 |
| i-times-i | 1, 0, 1, 0, 1, 0 | r=-1.0, i=0.0 |