1---
2version: 0.1.0
3precision: 3
4---
5# draftply — AC Impedance & Phase
6# "What's the impedance of my circuit, and how far behind is the current?"
7# Complex numbers carry magnitude and phase together — no separate lookup.
8
9defunit("V")
10defunit("A")
11defunit("Ohm", "V/A")
12
13# ── Measured phasors ────────────────────────────
14# Mains voltage as the phase reference (0°), and the current you measured —
15# it lags behind the voltage because the load is inductive.
16U = 230 V
17I = 1.8 - 1.3i A
18
19# ── Impedance ────────────────────────────────────
20# Division of two unit-carrying quantities derives the unit automatically,
21# same as for real numbers: V / A → Ohm.
22Z = U / I
23
24"Impedance Z": Z
25"Magnitude |Z| (Ω)": abs(Z)
26"Phase angle (°)": arg(Z) * 180 / pi
27"Resistive part R (Ω)": re(Z)
28"Reactive part X (Ω)": im(Z)
29
30# ── Add a series element ────────────────────────
31# The feed cable and connector add a small stray impedance in series —
32# impedances in series just add, real and imaginary parts together.
33Z_cable = 2 + 1i Ohm
34Z_total = Z + Z_cable
35
36"Total impedance incl. cable": Z_total
37"Total magnitude (Ω)": abs(Z_total)
38
39# ── Power ────────────────────────────────────────
40# S = U · I* splits cleanly into real (working) and reactive power.
41defunit("W", "V*A")
42S = U * conj(I)
43
44"Apparent power |S| (VA)": abs(S)
45"Real power P (W)": re(S)
46"Reactive power Q (var)": im(S)
47"Power factor": cos(arg(Z))
48