How to Find the Real and Imaginary Parts of a Polynomial
At a glance
- 1. Substitute the complex input
Write z as x + iy, with x and y real.
- 2. Expand the polynomial
Use z² = (x + iy)² and simplify powers and products.
- 3. Collect components
Group terms without i for the real part, and coefficients of i for the imaginary part.
- 4. Check with a CAS
In SymPy, expand the expression and apply re and im to the result.
If you want a calculator to split a polynomial into its real and imaginary parts, the key is to tell it what the complex input means. Write the input as , where and are real. Then expand and collect the real terms separately from the terms multiplied by .
The result has the form
where is the real part and is the imaginary part. A computer algebra system such as SymPy can do the expansion and separation symbolically. The same substitution-and-collecting method works by hand for small polynomials.
What “real and complex parts” usually means
For a complex number , its real part is and its imaginary part is . The imaginary part is the real-valued coefficient of ; it is not itself. For example, if , then and .
For a polynomial in a complex variable, the parts generally depend on both coordinates of the input. If has real coefficients, substituting still usually produces both a real part and an imaginary part. If the polynomial has complex coefficients, split those coefficients too as part of the expansion.
A worked example
Take
and let . First expand the cubic:
Next expand the linear term:
Adding the constant and grouping the terms gives
Therefore,
and
For a numerical check, choose , so and . The formulas give and , hence . Direct evaluation gives the same result.
Use SymPy as a symbolic calculator
In Python with SymPy installed, define and as real symbols. That assumption matters: without it, the system may not be able to simplify real-part and imaginary-part expressions fully.
from sympy import symbols, I, expand, re, im
x, y = symbols('x y', real=True)
z = x + I*y
p = z**3 + (2 - I)*z + 1
expanded = expand(p)
real_part = expand(re(expanded))
imaginary_part = expand(im(expanded))
print(real_part)
print(imaginary_part)
The output is
x**3 - 3*x*y**2 + 2*x + y + 1
3*x**2*y - y**3 - x + 2*y
The order of terms may differ, but the expressions are equivalent. For a different polynomial, replace the definition of p; keep x and y declared real and use z = x + I*y.
Common mistakes
- Calling the coefficient of the imaginary part incorrectly: For , the imaginary part is , not .
- Forgetting to declare and real: A symbolic system may retain unevaluated expressions involving real and imaginary-part operators if it does not know the variables are real.
- Treating a complex coefficient as real: For example, contributes to both parts after multiplication by .
- Confusing the polynomial’s coefficients with its output: A polynomial with real coefficients can still have a nonzero imaginary part when evaluated at a non-real input.
If the input is a specific complex number rather than , substitute its real and imaginary coordinates into and , or evaluate the polynomial directly and read off the two components.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.