二维矢量的幅值
Prerequisite: Linear Algebra | Defining a Vector
Linear algebra is the branch of mathematics concerning linear equations by using vector spaces and through matrices. In other words, a vector is a matrix in n-dimensional space with only one column. In the sequence of learning linear algebra using python, this is article 6. In linear algebra, the vector magnitude is given by:
线性代数是使用向量空间和矩阵的线性方程组的数学分支。 换句话说,向量是n维空间中只有一列的矩阵。 在使用python学习线性代数的序列中,这是第6条。在线性代数中,矢量幅值由下式给出:
In a scalar product, each component of the vector is multiplied by the same scalar value. As a result, the vector's length is increased by a scalar value.
在标量积中,向量的每个分量都乘以相同的标量值。 结果,向量的长度增加了一个标量值。
For example: Let a vector a = [4, 9, 7], then the magnitude of the vector is:
例如:设向量a = [4,9,7],则向量的大小为:
The python code calculates the magnitude of the vector by defining a function. Why do we need to separately build a function? - This is helpful for the case when you have to find magnitudes of multiple vectors multiple times.
python代码通过定义一个函数来计算向量的大小。 为什么我们需要分别构建一个函数? -当必须多次查找多个矢量的大小时,这很有用。
使用功能矢量幅值的Python代码 (Python code for Vector Magnitude using Function)
# Vectors in Linear Algebra Sequnce (7)
# Fuction defined for calculating magnitude
def magnitude(vec):
summ = 0
for i in range(len(vec)):
summ = vec[i]*vec[i] + summ
return pow(summ,0.5)
a = [2, 5, 2, 5, 14]
c = 3
b = []
print("Vector a = ", a)
summ = 0
print("Vector's magnitude = ", magnitude(a))
Output
输出量
Vector a = [2, 5, 2, 5, 14]
Vector's magnitude = 15.937377450509228
翻译自: https://www.includehelp.com/python/vector-magnitude-using-function.aspx
二维矢量的幅值