coding the matrix week1 Playing with Complex Field

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)
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容