二维矢量的幅值_使用功能的矢量幅值| 使用Python的线性代数

本文介绍了如何使用Python进行线性代数中的向量幅值计算。向量幅值是向量的长度,可以通过将每个分量乘以标量值来改变。示例展示了如何定义一个函数来计算多个二维向量的幅值。
摘要由CSDN通过智能技术生成

二维矢量的幅值

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.

在标量积中,向量的每个分量都乘以相同的标量值。 结果,向量的长度增加了一个标量值。

Vector Magnitude formula 1
Vector Magnitude formula 2

For example: Let a vector a = [4, 9, 7], then the magnitude of the vector is:

例如:设向量a = [4,9,7],则向量的大小为:

Vector Magnitude formula 3

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

二维矢量的幅值

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值