Project 18: Complex Plane Explorer

A self-contained deep-dive from the canonical Math from Foundations to Machine Learning curriculum.

  • Difficulty: Intermediate-Advanced
  • Time: 8-16 hours
  • Language: Python (alternatives: Julia, MATLAB/Octave, JavaScript)
  • Prerequisites: Projects 5 and 16
  • Source: HS P18

What You Will Build

Build a complex-number toolkit that parses rectangular values, converts between rectangular and polar forms, performs arithmetic, powers, and roots, and plots every result geometrically. Implement core operations from real/imaginary pairs rather than relying entirely on Python’s complex type; use the standard library only as a validation oracle. Show multiplication as scaling by modulus and rotation by argument, division as inverse scaling/rotation, and the n roots of a value as evenly spaced points. Include Euler-form demonstrations and careful branch conventions for principal arguments.

Real World Outcome

Entering 3+4i reports modulus 5, principal argument in radians/degrees, and a plotted vector. Multiplying by i visibly rotates it 90 degrees. Asking for fifth roots displays five points on the correct circle and verifies that raising each root to the fifth power reconstructs the input within tolerance. Round-trip rectangular→polar→rectangular errors are printed rather than hidden.

Core Question

How does adding one imaginary dimension turn multiplication into a geometric operation involving both rotation and scale?

Concepts You Must Understand First

  1. Imaginary unit and rectangular form: i^2=-1, with real and imaginary coordinates.
  2. Modulus and argument: distance from origin and directed angle, computed robustly with atan2.
  3. Polar multiplication/division: moduli multiply/divide while arguments add/subtract.
  4. Euler’s identity: e^(iθ)=cos θ+i sin θ links exponentials and rotations.
  5. Powers, roots, and branches: arguments differ by multiples of , creating multiple roots.

Build Milestones

  1. Define a rectangular complex value and tested addition, subtraction, multiplication, and division.
  2. Add modulus/argument and rectangular↔polar conversion with a documented principal-angle interval.
  3. Implement polar multiplication/division and integer powers; visualize before and after.
  4. Generate all nth roots, plot them, and verify power round-trips.
  5. Add parser, Euler-form display, tolerance reports, and comparisons with trusted complex arithmetic.

Hints in Layers

  1. Use atan2(imag, real), not atan(imag/real), to preserve quadrants and vertical directions.
  2. Normalize displayed angles consistently, but retain unwrapped angles when explaining repeated rotations.
  3. Roots have arguments (θ + 2πk)/n for k=0..n-1; stopping at the principal root loses valid answers.

Common Pitfalls and Debugging

  • Symptom: arguments are wrong in quadrants II and III. Cause: one-argument arctangent lost sign/quadrant information. Fix: use atan2 with tests on all axes/quadrants.
  • Symptom: only one square root appears. Cause: only the principal branch was generated. Fix: iterate all root indices.
  • Symptom: conversions fail near the negative real axis. Cause: equivalent angles π and were compared directly. Fix: compare reconstructed values or wrapped angular distance.

Definition of Done

  • Rectangular arithmetic agrees with hand and trusted-library cases.
  • Polar conversions handle every quadrant and round-trip within tolerance.
  • Multiplication/division visuals correctly show scale and rotation.
  • Powers and all nth roots are implemented and verified.
  • Principal-angle conventions and zero-value limitations are documented.

Previous: Project 17 · Complete learning path · Next: Project 19