01.向量是什麼
本節主要內容:二維向量->三維向量->向量的加法->向量的數乘.
1.二維向量
提示1:向量的起點可以在任何位置,我們一般假設在原點,向量具有固定長度和方向.
提示2:繪製大量向量時,每一個向量可以用一個點表示(假設起點為原點).
提示3:注意下圖,向量的橫坐標是-2,縱左邊是3,代表當以原點為起點時,箭頭位置在(-2,3).在python中,一般用[[-2],[3]]表示.
2.三維向量
提示:三維向量大概長這個樣子,注意右側矩陣的表示形式,是豎著排列的.在python中,一般用[[2],[1],[3]]表示.
3.向量的加法
提示:兩個向量的加法一般將第一個向量末尾作為第二個向量的起點.如下為[[2],[3]]+[[3],[2]]=[[5],[5]],因為這裡以原點作為第一個向量的起點,我們可以簡單看到兩個向量之和位於坐標(5,5).
另一個,按坐標軸拆解的例子:
4.向量的數乘
注意這裡x和y分別為原來的-1.5倍.
-1.5*[[2],[3]] = [[-3],[-4.5]].
下一篇地址:
袁傑雄:02.線性組合和張成空間和基<python線性代數>動畫代碼:
附註代碼1:
import numpy as npimport matplotlib.pyplot as pltfrom mpl_toolkits.axisartist.axislines import SubplotZerofrom moviepy.editor import VideoClipfrom moviepy.video.io.bindings import mplfig_to_npimagefrom pylab import *zhfont = mpl.font_manager.FontProperties(fname=/usr/share/fonts/truetype/wqy/wqy-microhei.ttc,size=13)plt.rcParams[axes.unicode_minus]=False #負號顯示解決方案plt.style.use("seaborn")def set_axis_middle(fig): ax = SubplotZero(fig, 111) fig.add_subplot(ax) for direction in ["xzero", "yzero"]: # adds arrows at the ends of each axis ax.axis[direction].set_axisline_style("-|>") # adds X and Y-axis from the origin ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: # hides borders ax.axis[direction].set_visible(False) ax.set_aspect(1.) #設置高寬比 ax.grid(True, zorder=0) ax.set_xlim(-5, 5) ax.set_ylim(-5, 5) return axfig = plt.figure()def update(second): num = second X,Y = -num/2,num/3 ax = set_axis_middle(fig) ax.quiver(X, Y, [-2], [3], angles=xy, scale_units=xy, scale=1) plt.text(X+0.2,Y-0.2,r"$[^{-2}_{3}]$", fontproperties=zhfont) print (num) return mplfig_to_npimage(fig)if 1: animation = VideoClip(update, duration = 2) animation.write_gif("2dvector.gif", fps=10)
附註代碼2:
import numpy as npimport matplotlib.pyplot as pltfrom mpl_toolkits.axisartist.axislines import SubplotZerofrom moviepy.editor import VideoClipfrom moviepy.video.io.bindings import mplfig_to_npimagefrom pylab import *zhfont = mpl.font_manager.FontProperties(fname=/usr/share/fonts/truetype/wqy/wqy-microhei.ttc,size=13)plt.rcParams[axes.unicode_minus]=False #負號顯示解決方案plt.style.use("seaborn")def set_axis_middle(fig): ax = SubplotZero(fig, 111) fig.add_subplot(ax) for direction in ["xzero", "yzero"]: # adds arrows at the ends of each axis ax.axis[direction].set_axisline_style("-|>") # adds X and Y-axis from the origin ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: # hides borders ax.axis[direction].set_visible(False) ax.set_aspect(1.) #設置高寬比 ax.grid(True, zorder=0) ax.set_xlim(-0, 5.5) ax.set_ylim(-0, 5.5) return axfig = plt.figure()def draw_vector(ax,x,y,u,v,c): ax.quiver(x,y, u,v,angles=xy, scale_units=xy, scale=1,color = c) plt.text(x+u/2,y+v/2,r"$[^{0}_{1}]$".format(u,v), fontproperties=zhfont)def update(second): num = second U,V = 2, 3 U2,V2 = 3,2 ax = set_axis_middle(fig) draw_vector(ax,0,0,U,V,"y") if second <= 1: X,Y = second*U/1,second*V/1 draw_vector(ax,X,Y,U2,V2,"r") else: draw_vector(ax,U,V,U2,V2,"r") draw_vector(ax,0,0,U+U2,V+V2,"g") print (num) return mplfig_to_npimage(fig)if 1: animation = VideoClip(update, duration = 3) animation.write_gif("test.gif", fps=10)
附註代碼3:
import numpy as npimport matplotlib.pyplot as pltfrom mpl_toolkits.axisartist.axislines import SubplotZerofrom moviepy.editor import VideoClipfrom moviepy.video.io.bindings import mplfig_to_npimagefrom pylab import *zhfont = mpl.font_manager.FontProperties(fname=/usr/share/fonts/truetype/wqy/wqy-microhei.ttc,size=13)plt.rcParams[axes.unicode_minus]=False #負號顯示解決方案plt.style.use("seaborn")def set_axis_middle(fig): ax = SubplotZero(fig, 111) fig.add_subplot(ax) for direction in ["xzero", "yzero"]: # adds arrows at the ends of each axis ax.axis[direction].set_axisline_style("-|>") # adds X and Y-axis from the origin ax.axis[direction].set_visible(True) for direction in ["left", "right", "bottom", "top"]: # hides borders ax.axis[direction].set_visible(False) ax.set_aspect(1.) #設置高寬比 ax.grid(True, zorder=0) ax.set_xlim(-5, 5) ax.set_ylim(-5, 5) return axfig = plt.figure()def draw_vector(ax,x,y,u,v,c,s="",s2=""): ax.quiver(x,y, u,v,angles=xy, scale_units=xy, scale=1,color = c) if s == "": plt.text(x+u/2,y+v/2,r"$[^{"+str(u)+"}_{"+str(v)+"}]$", fontproperties=zhfont) else: plt.text(x+u/2,y+v/2,s2 + r"$vec{"+s+"}$", fontproperties=zhfont)def update(second): num = second U,V = 2, 3 rate = -1.5 ax = set_axis_middle(fig) if second <= 1: draw_vector(ax,0,0,U,V,"y","v") elif second <= 2: draw_vector(ax,0,0,U,V,"y","v") U2,V2 = (second-1)*U*rate,(second-1)*V*rate draw_vector(ax,0,0,U2,V2,"r","v","{0}".format(rate)) else: second = 2 draw_vector(ax,0,0,U,V,"y") U2,V2 = (second-1)*U*rate,(second-1)*V*rate draw_vector(ax,0,0,U2,V2,"r") print (num) return mplfig_to_npimage(fig)if 1: animation = VideoClip(update, duration = 4) animation.write_gif("test.gif", fps=10)
推薦閱讀:
※線性方程組(5)-克雷洛夫子空間與伽遼金原理
※10935 梯度、散度、旋度、Jacobian、Hessian、Laplacian 的關係圖
※線性代數: 線性空間與線性映射(3)
※矩陣的四個子空間及其聯繫