Team 10

Complex Number Calculator

Build an app that performs arithmetic on complex numbers — addition, subtraction, multiplication, division — and converts between rectangular (a+bi) and polar (r∠θ) forms.

🎯 Learning Goals

  • Master the algebra of the Imaginary Unit 'i'
  • Convert between Rectangular and Polar coordinate systems
  • Calculate Modulus (magnitude) and Argument (angle)
  • Implement trigonometry-based coordinate transformations

🌎 Why This Matters

Complex numbers are essential for modern electronics. Everything from your smartphone's wireless communication to the power lines on your street uses complex numbers for calculations. They allow engineers to describe 'waves' and 'oscillations' easily.

📖Understanding Complex Numbers

Theory Masterclass
"

A complex number has two parts: a real part and an imaginary part. Written as: z = a + bi, where 'a' is real, 'b' is imaginary, and i = √(-1). Example: z₁ = 3 + 4i means a=3, b=4. Operations: Addition: (a+bi) + (c+di) = (a+c) + (b+d)i Subtraction: (a+bi) - (c+di) = (a-c) + (b-d)i Multiplication: (a+bi)(c+di) = (ac-bd) + (ad+bc)i Division: (a+bi)/(c+di) = [(ac+bd) + (bc-ad)i] / (c²+d²) Modulus: |z| = √(a² + b²) — the "distance" from origin Argument: arg(z) = arctan(b/a) — the angle from the positive x-axis Polar Form: z = r(cosθ + i·sinθ) = r∠θ where r = |z| (modulus) and θ = arg(z) (argument) Converting: Rectangular → Polar: r = √(a²+b²), θ = arctan(b/a) Polar → Rectangular: a = r·cosθ, b = r·sinθ

Mathematical Foundation

fxAddition: (a+bi) + (c+di) = (a+c) + (b+d)i
fxMultiplication: (a+bi)(c+di) = (ac-bd) + (ad+bc)i
fxModulus: |z| = √(a² + b²)
fxArgument: θ = arctan(b/a)
fxPolar: z = r∠θ where r=|z|, θ=arg(z)

🎨Part A — Designer View (UI Design)

Open MIT App Inventor → Switch to Designer view. Follow each step below to build the interface.

1

1. Designer Overview

• Set **Screen1** title to "Complex Numbers Tool". • Center all elements. • Use a professional dark theme (Black background).

2

2. Complex Number A Input

• Drag a **HorizontalArrangement**. • Put 2 **TextBoxes** inside. Rename: 'RealA' and 'ImagA'. • Set **Width** to 40% each. • Add a **Label** in between with text "+" and one at the end with text "i".

3

3. Operation Buttons

• Drag another **HorizontalArrangement**. • Add 2 **Buttons**: 'AddBtn' (Text: "+") and 'MultBtn' (Text: "×"). • Make them large and easy to tap.

4

4. Result Display

• Drag a **Label** to the bottom. • Rename it to 'ResultLbl'. • Set **FontSize** to 20, **Text** to "Answer: 0 + 0i".

🧩Part B — Blocks View (Logic & Calculation)

Switch to Blocks view. Now add the logic that makes your app actually work.

1

1. Switch to Blocks

• Click the **Blocks** button at the top right of the Designer.

2

2. Complex Addition

• Drag 'when AddBtn.Click' (Gold). • Complex addition is (RealA + RealB) + (ImagA + ImagB)i. • Go to **Math** (Blue). Drag '+' blocks. • [set global ResultReal] to [RealA.Text + RealB.Text]. • [set global ResultImag] to [ImagA.Text + ImagB.Text].

3

3. Complex Multiplication

• Formula: (ac-bd) + (ad+bc)i. • Get '-' and '*' and '+' blocks from **Math** (Blue). • Real Part: ([RealA * RealB] - [ImagA * ImagB]). • Imaginary Part: ([RealA * ImagB] + [ImagA * RealB]).

4

4. Formatting the i

• Go to the **Text** drawer (Bright Pink). Drag a 'join' block. • Snap them: [set ResultLbl.Text to] [join] [ResultReal] [" + "] [ResultImag] ["i"].

🧪Testing Your App

  • (3+4i) + (1+2i) = 4+6i
  • (3+4i) × (1+2i) = (3-8) + (6+4)i = -5+10i
  • |3+4i| = 5 (classic 3-4-5)
  • (1+i) ÷ (1-i) = i (pure imaginary result)
  • Polar form of 1+i = √2 ∠ 45°

🚀Bonus Challenges

Extra credit — impress your instructor

  • Plot complex numbers on an Argand diagram using Canvas
  • Add powers: z^n using De Moivre's theorem
  • Add nth roots of a complex number
  • Show the multiplication geometrically (rotation and scaling)