coding the matrix week1 Playing
We interpret the real and imaginary parts of a complex number as x and y coordinates.
Let's plot a longer list of complex numbers, one derived from an image.
#install matplotlib and seaborn
from plotting import plot
L = [2+2j, 3+2j, 1.75+1j, 2+1j]
plot(L)
Now, we'll define a collection of complex numbers based on the intensities of the pixels in the image and plot that.
The plot function takes an optional second argument, given the scale of the plot.And an optional third argument, given the size in pixels of the points displayed.
from image import *
from plotting import plot
I = color2gray(file2image("img01.png"))
r = len(I)
c = len(I[0])
M = [x + y*1j for x in range(c) for y in range(r) if I[r-y-1][x] < 120]
plot(M, max(r,c), 1)
f (z) = z + (1 + 2i) is called a translation
#install matplotlib and seaborn
from plotting import plot
L = [2+2j, 3+2j, 1.75+1j, 2+1j]
plot({z + (1+2j) for z in L})
plot([z - (c/2 + (r/2)*1j) for z in M], max(r,c), 1) #图像中心化
We can choose anywhere to put its tail and one convenient place to put it is at the origin.And the head should be at the location with x-coordinate minus 6 and y-coordinate 5.
Now, what about the functional composition? The functional composition add z1 plus z2 to its input.You can find that arrow by choosing its tail to be the tail of the first arrow, and its head to be the head of the second arrow. So, we see that addition of complex numbers can be represented by putting arrows together.
Scaling(缩放)
from image import *
from plotting import plot
I = color2gray(file2image("img01.png"))
r = len(I)
c = len(I[0])
M = [x + y*1j for x in range(c) for y in range(r) if I[r-y-1][x] < 120]
L = [2+2j, 3+2j, 1.75+1j, 2+1j]
plot({0.5*z for z in L})
plot({0.5*z for z in M}, r, 1)
Reflection
plot({-1*z for z in L})
plot({-1*z for z in M}, r, 1)
image.png
image.png
The argument of a complex number is the angle, measured in radians, between the x-axis and the arrow representing the complex number.
Euler's formula states that for any real number theta, e to the theta times i is the point z in the complex plane on the unit circle whose argument is theta.
image.png
from math import pi, e
plot([e**(t*2*pi*1j/20) for t in range(20)])
旋转特性
plot([e**(pi*1j/4)*z for z in L])
plot([e**(pi*1j/4)*z for z in M], r, 1)