Python handles computation with relative ease. Python uses "j" for the imaginary number.
%pylab inline
z1 = 1+2j
z1
z2 = 3-3j
z1+z1, z1-z2
z1*z2, z1/z2
abs(z1), angle(z1)
abs(z1*z2)-abs(z1)*abs(z2)
angle(z1*z2) - angle(z1) - angle(z2)
w = 1/z1
z1*w, angle(w)+angle(z1), angle(z1*w)
z1*conj(z1)-abs(z1)**2
Euler's formula says \[\exp(\theta) = \cos(\theta) + j\sin(\theta)\].
If we put in a general complex number, we get the following: \[\exp(x+jy) = \exp(x)(\cos(y)+j\sin(y))\]
exp(z1)
real(exp(z1)), imag(exp(z1))
exp(z1).real, exp(z1).imag
x,y = z1.real, z1.imag
exp(z1) - exp(x)*(cos(y)+1j*sin(y))
z = 1+1j*sqrt(3)
a = array([z,1/z,conj(z),conj(1/z)])
#plot unit circle
t = linspace(0,2*pi,101)
plot(cos(t),sin(t))
#plot data
plot(a.real, a.imag,'ro')
#make box bigger
axes().set_aspect('equal')
m = max(max(abs(a.real)),max(abs(a.imag)))
xlim(-1.1*m,1.1*m),ylim(-1.1*m,1.1*m)
#draw horizontal and vertical axes
plot([0,0],[-1.1*m,1.1*m],'k',linewidth=0.5)
plot([-1.1*m,1.1*m],[0,0],'k',linewidth=0.5)
#annotate plot with labels
text(z.real+0.1, z.imag,'$z$',fontsize=15)
text((1/z).real+0.1, (1/z).imag, '$1/z$', fontsize=15)
text(conj(z).real+0.1, conj(z).imag, '$z^*$',fontsize=15)
text(conj(1/z).real+0.1, conj(1/z).imag, '$1/z^*$',fontsize=15)
We could use functions in the numpy.polynomial library, but will use functions in the signal processing library instead. We need the signal library for other things, so let's start here.
import scipy.signal as sig
\(b\) below is our polynomial coefficients. In this case, \(b(x) = x^2 + 3x+2\).
b = array([1,3,2])
Square b(x).
convolve(b,b)
The zeros of this polynomial are -2 and -1. z below is a list of the zeros.
a = [1]
z, p, k = sig.tf2zpk(b,a)
z, p, k
We can invert the representation: given the zeros, compute the polynomial in the conventional monomial representation.
astar, bstar = sig.zpk2tf(z,p,k)
astar, bstar
Ok, we've demonstrated how to factor polynomials. Now look at what happens when the zeros are complex.
b = array([1,0,1])
z,p,k = sig.tf2zpk(b,a)
z,p,k
sig.zpk2tf(z,p,k)