Introduction
Finding the square roots of the complex number is a fundamental skill in algebra and engineering that lets you solve equations that involve the imaginary unit i (where i² = −1). Whether you are balancing electrical circuits, analyzing waveforms, or simply expanding your mathematical toolkit, understanding how to extract both the principal and secondary square roots of any complex number opens the door to more advanced topics such as complex analysis, signal processing, and control theory. This article walks you through the theory, step‑by‑step procedures, and practical examples so you can confidently compute √(a + bi) for any real numbers a and b.
Understanding Complex Numbers
A complex number is written as z = a + bi, where a is the real part, b is the imaginary coefficient, and i is the imaginary unit. The set of all such numbers forms the complex plane, with the horizontal axis representing real values and the vertical axis representing imaginary values. The modulus (or absolute value) of z is |z| = √(a² + b²), and the argument (or angle) θ is measured from the positive real axis to the line joining the origin to the point (a, b). These two quantities—modulus and argument—are crucial when we need to find square roots using polar representation Less friction, more output..
Methods to Find Square Roots
There are two mainstream approaches: the algebraic method, which solves a system of equations directly, and the polar form method, which leverages De Moivre’s theorem for a more intuitive geometric interpretation And it works..
Algebraic Method
Suppose we want √(a + bi) = x + yi, where x and y are real numbers. Squaring both sides gives:
(x + yi)² = a + bi
=> x² – y² + 2xy i = a + bi
Equating real and imaginary parts yields the system:
- x² – y² = a
- 2xy* = b
Solving this system typically involves expressing y in terms of x (or vice‑versa) from the second equation, substituting into the first, and solving a quadratic. The algebraic route is useful for simple numbers but can become cumbersome for larger coefficients.
Polar Form Method (De Moivre’s Theorem)
Any complex number can be expressed in polar form as z = r · (cos θ + i sin θ), where r = |z| and θ = arg(z). De Moivre’s theorem states that for any integer n:
[ r·(cosθ + i sinθ) ]ⁿ = rⁿ·(cos nθ + i sin nθ)
To find the square root, set n = ½. This gives two distinct roots because the argument can be increased by 2π:
√z = √r·[ cos( (θ + 2kπ) / 2 ) + i sin( (θ + 2kπ) / 2 ) ], k = 0, 1
The first root (k = 0) is the principal square root, while the second (k = 1) is its opposite in the complex plane.
Step‑by‑Step Procedure
Below is a clear workflow you can follow for any complex number z = a + bi.
-
Compute the modulus
r = √(a² + b²)Use a calculator for accuracy, especially when a and b are large And it works..
-
Determine the argument
θ = atan2(b, a) // returns angle in radians between –π and πatan2 is preferred over simple arctan because it correctly handles all quadrants.
-
Find the square‑root modulus
√r = √(r) -
Calculate the two arguments
θ₁ = (θ + 2·0·π) / 2 = θ / 2 θ₂ = (θ + 2·1·π) / 2 = (θ + 2π) / 2 -
Convert back to rectangular form (optional, for most applications)
x₁ = √r · cos θ₁ y₁ = √r · sin θ₁ √z₁ = x₁ + y₁ iRepeat with θ₂ to obtain the second root √z₂ Practical, not theoretical..
-
Verify (optional but recommended)
Square each root and check that you recover the original a + bi (allowing for rounding errors).
Tip: When b = 0 (a purely real number), the square roots simplify to ±√a, but remember that √(–a) for a > 0 yields purely imaginary roots ±i√a.
Practical Examples
Example 1: √(3 + 4i)
- r = √(3² + 4²) = √(9 + 16) = √25 = 5
- θ = atan2(4, 3) ≈ 0.9273 rad (≈ 53.13°)
- √r = √5 ≈ 2.2361
- θ₁ = 0.9273 / 2 ≈ 0.4636 rad (≈ 26.57°)
θ₂ = (0.9273 + 2π) / 2 ≈ (0.9273 + 6.2832) / 2 ≈ 3.6053 rad (≈ 206.57°) - Convert:
- √z₁ = 2.2361·(cos 0.4636 + i sin 0.4636) ≈ 2.2361·(0.8944 + i 0.4472) ≈ 2 + i
- √z₂ = 2.2361·(cos 3.6053 + i sin 3.6053) ≈ 2.2361·(–0.8944 – i 0.4472) ≈ –2 – i
Both roots satisfy (2 + i)² = 3 + 4i and (–2 – i)² = 3 + 4i.
Example 2: √(–5 + 12i)
r* = √((–5)² + 12²) = √(25 + 144) = √169 = 13
2. On the flip side, θ = atan2(12, –5) ≈ 1. 9656 rad (≈ 112.62°)
Note: Since the real part is negative and the imaginary part positive, the angle lies in Quadrant II; atan2 handles this automatically.
3. Here's the thing — √r = √13 ≈ 3. 6056
4. Now, θ₁ = 1. But 9656 / 2 ≈ 0. 9828 rad (≈ 56.That's why 31°)
θ₂ = (1. 9656 + 2π) / 2 ≈ (1.9656 + 6.Consider this: 2832) / 2 ≈ 4. So naturally, 1244 rad (≈ 236. 31°)
5. That's why convert:
- √z₁ = 3. Think about it: 6056·(cos 0. Plus, 9828 + i sin 0. That's why 9828) ≈ 3. 6056·(0.5547 + i 0.On top of that, 8321) ≈ 2 + 3i
- √z₂ = 3. Which means 6056·(cos 4. 1244 + i sin 4.Plus, 1244) ≈ 3. 6056·(–0.5547 – i 0.
Verification: (2 + 3i)² = 4 + 12i + 9i² = 4 + 12i – 9 = –5 + 12i.
Example 3: √(–7 – 24i) (Third‑Quadrant Case)
- r = √((–7)² + (–24)²) = √(49 + 576) = √625 = 25
- θ = atan2(–24, –7) ≈ –1.8506 rad (≈ –106.26°)
Equivalently, θ ≈ 4.4326 rad (2π – 1.8506) if a positive principal argument is preferred. - √r = 5
- θ₁ = –1.8506 / 2 ≈ –0.9253 rad (≈ –53.13°)
θ₂ = (–1.8506 + 2π) / 2 ≈ 2.2163 rad (≈ 126.87°) - Convert:
- √z₁ = 5·(cos(–0.9253) + i sin(–0.9253)) ≈ 5·(0.6 – i 0.8) = 3 – 4i
- √z₂ = 5·(cos 2.2163 + i sin 2.2163) ≈ 5·(–0.6 + i 0.8) = –3 + 4i
Verification: (3 – 4i)² = 9 – 24i + 16i² = 9 – 24i – 16 = –7 – 24i.
Common Pitfalls and Tips
- Argument Ambiguity: Always use
atan2(y, x)(or your language’s equivalent) rather thanarctan(y/x). The two-argument function distinguishes between quadrants (e.g., (–1, –1) vs. (1, 1)), preventing a π radian error in θ that would rotate the roots by 90°. - Principal Root Convention: The principal square root is defined as the root with argument in (–π/2, π/2] (i.e., non‑negative real part). If the real part is zero, the principal root has a non‑negative imaginary part. This is the value returned by most programming libraries (e.g.,
cmath.sqrtin Python,std::sqrtforstd::complexin C++). - Numerical Stability: For very large or very small a and b, computing r = √(a² + b²) can overflow or underflow. A strong implementation scales the inputs: if |a| > |b|, compute r = |a|√(1 + (b/a)²); otherwise r = |b|√(1 + (a/b)²).
- Algebraic Shortcut: When a and b are integers and
Algebraic Shortcut: When a and b are integers and the modulus r = √(a² + b²) happens to be a perfect square, the square roots often have integer (or simple rational) real and imaginary parts. In such cases, you can solve the system
x² – y² = a
2xy = b
directly for integers x and y. For √(3 + 4i), we need x² – y² = 3 and 2xy = 4 ⇒ xy = 2. Testing factor pairs of 2 (±1, ±2) quickly yields x = 2, y = 1 (or x = –2, y = –1), giving the roots 2 + i and –2 – i without any trigonometry. This “guess-and-check” method is extremely fast for contest problems or simple exact values Most people skip this — try not to..
Algebraic Derivation (The Cartesian Method)
For completeness, the square root x + iy of a + ib can be found purely algebraically by solving:
- x² – y² = a
- 2xy = b
Squaring and adding the equations gives (x² + y²)² = a² + b² = r², so x² + y² = r (taking the non-negative root).
Adding this to equation (1): 2x² = r + a ⇒ x = ±√((r + a)/2)
Subtracting (1) from it: 2y² = r – a ⇒ y = ±√((r – a)/2)
This changes depending on context. Keep that in mind But it adds up..
The signs of x and y are not independent; they must satisfy 2xy = b. Because of this, sign(x) = sign(y) if b > 0, and sign(x) ≠ sign(y) if b < 0. If b = 0, the number is real and the problem reduces to the real square root But it adds up..
This yields the explicit Cartesian Formula:
√(a + ib) = ± [ √((r + a)/2) + i · sign(b) √((r – a)/2) ] (where sign(0) = 1 by convention for the principal root)
Example 1 Revisited (3 + 4i):
r = 5.
x = √((5 + 3)/2) = √4 = 2.
y = sign(4) · √((5 – 3)/2) = +√1 = 1.
Roots: 2 + i, –2 – i.
Example 3 Revisited (–7 – 24i):
r = 25.
x = √((25 – 7)/2) = √9 = 3.
y = sign(–24) · √((25 + 7)/2) = –√16 = –4.
Roots: 3 – 4i, –3 + 4i.
This algebraic form is often preferred in numerical libraries because it avoids trigonometric function calls and handles the sign logic explicitly, reducing rounding errors near the axes Nothing fancy..
Quick Reference Card
| Step | Polar Method | Cartesian (Algebraic) Method |
|---|---|---|
| 1. Magnitude | √r | (Implicit in formulas below) |
| 4. Modulus | r = √(a² + b²) | r = √(a² + b²) |
| 2. Day to day, argument | θ = atan2(b, a) | (Skip) |
| 3. Angles | θ₁ = θ/2; θ₂ = θ/2 + π | (Skip) |
| 5. Components | x = √r cos θ₁; y = √r sin θ₁ | x = √((r + a)/2)<br>y = sign(b) √((r – a)/2) |
| **6. |
Minimal Python Implementation
import cmath
import math
def csqrt_polar(z):
"""Polar method
```python
import cmath
import math
def csqrt_polar(z: complex) -> tuple[complex, complex]:
"""
Compute the two square‑roots of a complex number using the polar method.
polar returns (r, theta) with r >= 0 and theta in (-π, π]
r, theta = cmath.Even so, returns a tuple (r1, r2) where r2 = -r1. sqrt(r)
# Half‑angle for the principal root
theta_half = theta / 2.Even so, polar(z)
# Principal square‑root magnitude
r_sqrt = math. """
# cmath.0
# Build the two roots
root1 = cmath.
def csqrt_cartesian(z: complex) -> tuple[complex, complex]:
"""
Compute the two square‑roots of a complex number using the algebraic (Cartesian) formulas.
Day to day, """
a, b = z. Returns a tuple (r1, r2) where r2 = -r1.
real, z.imag
# Modulus
r = math.hypot(a, b) # sqrt(a*a + b*b)
# Guard against degenerate cases where r == 0
if r == 0.
# Common denominator 2
two = 2.0
# Compute x and y magnitudes
x_mag = math.sqrt((r + a) / two)
y_mag = math.
# Determine the sign of y according to the sign of b
# sign(b) = 1 if b > 0, -1 if b < 0, and 1 (principal) when b == 0
sign_b = 1 if b >= 0 else -1
x = x_mag
y = sign_b * y_mag
# The second root is simply the negative of the first
root1 = complex(x, y)
root2 = -root1
return root1, root2
# ----------------------------------------------------------------------
# Demonstration and sanity‑check
if __name__ == "__main__":
test_numbers = [
3 + 4j,
-7 - 24j,
1 + 0j,
0 + 5j,
-2 - 2j,
2.5 - 1.3j,
]
for z in test_numbers:
p1, p2 = csqrt_polar(z)
c1, c2 = csqrt_cartesian(z)
# Verify that both methods agree (up to rounding)
assert abs(p1 - c1) < 1e-12 or abs(p1 + c1) < 1e-12, f"Polar/Cartesian mismatch for {z}"
assert abs(p2 - c2) < 1e-12 or abs(p2 + c2) < 1e-12, f"Polar/Cartesian mismatch for {z}"
# Verify that squaring each root reproduces the original number
assert abs(p1 * p1 - z) < 1e-12, f"Root squaring failed for {z}"
assert abs(p2 * p2 - z) < 1e-12, f"Root squaring failed for {z}"
print(f"z = {z:>10}")
print(f" Polar roots : {p1:>10.Here's the thing — 6f} , {p2:>10. Also, 6f}")
print(f" Cartesian : {c1:>10. 6f} , {c2:>10.
### Why Two Implementations?
* **Polar method** – Leverages built‑in trigonometric functions (`cmath.rect`, `cmath.polar`). It is concise and mirrors the
mathematical definition $z = r e^{i\theta} \implies \sqrt{z} = \sqrt{r} e^{i\theta/2}$. Because it delegates the heavy lifting to the C standard library, it handles branch cuts and special values (infinities, NaNs) consistently with the platform’s `libm` implementation. Even so, it incurs the overhead of two transcendental function calls (`atan2` inside `polar`, `cos`/`sin` inside `rect`), which can be a bottleneck in tight numerical loops.
* **Cartesian method** – Uses only algebraic operations (`sqrt`, `hypot`, basic arithmetic). It avoids trigonometry entirely, making it significantly faster on most architectures—often 2× to 5× quicker in microbenchmarks. The formulas derive from solving $(x+iy)^2 = a+ib$ for real $x, y$:
$x = \pm\sqrt{\frac{r+a}{2}}, \quad y = \pm\sqrt{\frac{r-a}{2}} \quad \text{with} \quad \operatorname{sign}(y) = \operatorname{sign}(b)$
This approach is numerically stable for most inputs, but it requires care when $a \approx -r$ (i.e., $z$ near the negative real axis), where catastrophic cancellation in $(r-a)$ can degrade precision. The implementation above mitigates this by computing $y$ via the magnitude $\sqrt{(r-a)/2}$ and applying the sign of $b$ explicitly, preserving the correct quadrant.
### Choosing the Right Tool
| Scenario | Recommended Method |
| :--- | :--- |
| **General-purpose / Correctness-critical** | **Polar** (`csqrt_polar`). |
| **Inputs near negative real axis** | **Polar** preferred, or use a fused `hypot`/`sqrt` variant (e.Practically speaking, |
| **High-performance loops / Real-time DSP / Embedded** | **Cartesian** (`csqrt_cartesian`). g.sqrt` semantics exactly; handles IEEE-754 edge cases (signed zeros, NaNs, infinities) automatically. On the flip side, , Kahan’s algorithm) to avoid cancellation in the Cartesian formula. Which means matches `cmath. So |
| **Educational / Algorithmic clarity** | **Cartesian**. Consider this: lower latency, no transcendental calls, deterministic execution time. Exposes the algebraic structure of complex square roots without hiding it inside library calls.
### A Note on Branch Cuts and Principal Values
Both functions return the *principal* square root as the first element of the tuple (the one with non-negative real part, or non-negative imaginary part if the real part is zero). g.So this aligns with the standard branch cut for $\sqrt{z}$ along the negative real axis. But if your application requires a different branch convention (e. The second root is always the additive inverse. , for Riemann surface traversal), you would adjust `theta_half` in the polar version or the `sign_b` logic in the Cartesian version accordingly.
### Final Thoughts
Implementing complex square roots from scratch is a rite of passage for numerical programmers. And it forces you to confront floating-point subtleties—cancellation, branch cuts, signed zeros—that high-level libraries usually sweep under the rug. The polar method is your safety net: solid, standard-compliant, and readable. The Cartesian method is your scalpel: sharp, fast, and demanding of respect for its edge cases.
In production code, **default to `cmath.Also, sqrt`** (or `csqrt_polar` if you need both roots explicitly). It is battle-tested, hardware-accelerated on many platforms via vector math libraries, and correctly implements the IEEE-754 / C99 annex G specifications for complex arithmetic. Reach for the Cartesian formulation only when profiling proves the trigonometric overhead is a genuine bottleneck, and you have validated the numerical behavior for your specific input domain.