线性代数2-线性组合

作者: 赵阳_c149 | 来源:发表于2019-12-10 14:27 被阅读0次

    线性组合定义

    一般来说,线性组合是指将标量与向量相乘,并将这些项相加。

    当某个向量可以定义为其他向量的线性组合时,它们是一组线性相关的向量。

    当一组向量中的每个向量都无法定义为其他向量的线性组合时,它们是一组线性不相关的向量。

    判断一组向量是否为线性相关集合的最简单方式是采用行列式

    张成

    如果 \vec{v_1}, \vec{v_2},....., \vec{v_n} \in \mathbb{R} 那么,这些向量的张成(有时候也称为线性张成)是指这些向量的所有可能的线性组合。

    从数学角度来讲,向量集合\vec{v_1}, \vec{v_2},....., \vec{v_n}的张成表示为:

    Sp(\vec{v_1}, \vec{v_2},....., \vec{v_n})

    确定向量的张成

    假设有一对向量\vec{v}\vec{w},我们想要判断它们的张成中是否存在第三个向量\vec{t},表示\vec{t}可以写成向量对\vec{v}\vec{w}的线性组合。

    可以表示为:

    𝑎\vec{v} + 𝑏\vec{w} =\vec{t}, 其中\vec{v}\vec{w}分别乘以标量 𝑎 和 𝑏 ,然后相加生成向量\vec{t}

    如果我们能够找到一组使上式成立的标量 𝑎 和 𝑏 ,那么\vec{t}位于\vec{v}\vec{w} 的张成内。否则,如果没有使上式成立的标量 𝑎 和 𝑏 ,那么\vec{t} 不在它们的张成内。

    实例

    如果向量的值如下所示:​
    \vec{v}=\begin{bmatrix} 1\\3 \end{bmatrix}
    \vec{w}=\begin{bmatrix} 2\\5 \end{bmatrix}
    \vec{t}=\begin{bmatrix} 4\\11 \end{bmatrix}

    可以将 𝑎𝑣⃗ +𝑏𝑤⃗ =𝑡⃗ 重新写成:​
    𝑎\begin{bmatrix} 1\\3 \end{bmatrix}+𝑏\begin{bmatrix} 2\\5 \end{bmatrix}=\begin{bmatrix} 4\\11 \end{bmatrix}

    在线性代数课程中,可以手动求解这个问题:使用简化的梯阵形式,并将上式重写为增广矩阵。我们在下面提供了上式的增广矩阵:
    \begin{bmatrix}1\ 2 \ |4\\ 3 \ 5 \ |11 \end{bmatrix}

    注意,增广矩阵的右侧包含向量\vec{t}。我们要判断此向量是否位于另外两个向量\vec{v}\vec{w}的张成内。我们要检查其张成的另外两个向量组成了增广矩阵的左侧。

    求解简化的方程组

    向量与标量的线性组合将延伸出以下这个重要概念: 线性方程组
    在这里,仅介绍有两个方程和两个变量的方程组。

    在更宽泛的线性代数课程中,可以详细了解 含有n 个线性方程的方程组,其中n可以是任何数字。

    python演示

    # Makes Python package NumPy available using import method
    import numpy as np
    
    # Creates matrix t (right side of the augmented matrix).
    t = np.array([4, 11])
    
    # Creates matrix vw (left side of the augmented matrix).
    vw = np.array([[1, 2], [3, 5]])
    
    # Prints vw and t
    print("\nMatrix vw:", vw, "\nVector t:", t, sep="\n")
    
    • 使用 NumPy 的 linalg.solve 函数检查向量是否位于另外两个向量的张成内
      函数参数
      set_of_vectors 是增广矩阵的左侧。该参数表示你要检查其张成的向量集合(例如\vec{v}\vec{w})。
      vector_to_check 是增广矩阵的右侧。该参数表示检查是否位于向量 set_of_vectors 的张成内的向量。
      返回的变量
      vector_of_scalars 包含将求解方程组的标量,前提是所检查的向量位于向量组的张成内。否则,它将是一个空向量。
    def check_vector_span(set_of_vectors, vector_to_check):
        # Creates an empty vector of correct size
        vector_of_scalars = np.asarray([None]*set_of_vectors.shape[0])
        
        # Solves for the scalars that make the equation true if vector is within the span
        try:
            # TODO: Use np.linalg.solve() function here to solve for vector_of_scalars
            vector_of_scalars = np.linalg.solve(set_of_vectors, vector_to_check)
            if not (vector_of_scalars is None):
                print("\nVector is within span.\nScalars in s:", vector_of_scalars)
        # Handles the cases when the vector is NOT within the span   
        except Exception as exception_type:
            if str(exception_type) == "Singular matrix":
                print("\nNo single solution\nVector is NOT within span")
            else:
                print("\nUnexpected Exception Error:", exception_type)
        return vector_of_scalars
    
    
    • 求解方程组的标量
    # Call to check_vector_span to check vectors in Equation 1
    print("\nEquation 1:\n Matrix vw:", vw, "\nVector t:", t, sep="\n")
    s = check_vector_span(vw,t)
    
    # Call to check a new set of vectors vw2 and t2
    vw2 = np.array([[1, 2], [2, 4]]) 
    t2 = np.array([6, 12])
    print("\nNew Vectors:\n Matrix vw2:", vw2, "\nVector t2:", t2, sep="\n")    
    # Call to check_vector_span
    s2 = check_vector_span(vw2,t2)
    
    # Call to check a new set of vectors vw3 and t3
    vw3 = np.array([[1, 2], [1, 2]]) 
    t3 = np.array([6, 10])
    print("\nNew Vectors:\n Matrix vw3:", vw3, "\nVector t3:", t3, sep="\n")    
    # Call to check_vector_span
    s3 = check_vector_span(vw3,t3)
    

    方程组的解

    方程组的解始终是三种潜在情况之一。当向量位于张成内时,有一个解,如上面的示例所示。当向量位于张成内时,有一个解或无穷多解;当向量不在张成内时,无解。

    • 情形 1 - 一个解
      可以将之前的式子看做以下二元方程组:
      𝑥+2𝑦=4
      3𝑥+5𝑦=11
      其中𝑥=2并且𝑦=1。
      这意味着,当向量位于张成中时,方程组有一个解。用图形表示的话,这个唯一解是线相交的点(在下图中为红点)。
    %matplotlib inline
    import matplotlib.pyplot as plt
    plt.plot([4,0],[0,2],'b',linewidth=3)
    plt.plot([3.6667,0],[0,2.2],'c-.',linewidth=3)
    plt.plot([2],[1],'ro',linewidth=3)
    plt.xlabel('Single Solution')
    plt.show()
    
    • 情形 2 - 无穷多解
      第二种情形是标量值有无穷个,因为至少有两个方程是多余的。在我们的示例中,唯一的两个方程是多余的,它们表示同一条线。
      𝑥+2𝑦=6
      2𝑥+4𝑦=12
      其中任何𝑥和𝑦都使该方程组成立,因为这两个方程是多余的。
    import matplotlib.pyplot as plt
    plt.plot([6,0],[0,3],'b',linewidth=5)
    plt.plot([1,4,6,0],[2.5,1,0,3],'c-.',linewidth=2)
    plt.xlabel('Redundant Equations')
    plt.show()
    
    • 情形 3 - 无解
      第三种情形是没有标量值可以同时求解所有方程。 在我们的示例中,唯一的两个方程表示为两条平行线,因为它们无解。
      ​𝑥+2𝑦=6
      𝑥+2𝑦=10
      其中没有任何 𝑥 和 𝑦 可以使方程组成立。
    import matplotlib.pyplot as plt
    plt.plot([10,0],[0,5],'b',linewidth=3)
    plt.plot([0,6],[3,0],'c-.',linewidth=3)
    plt.xlabel('No Solution')
    plt.show()
    

    参考:
    linalg

    相关文章

      网友评论

        本文标题:线性代数2-线性组合

        本文链接:https://www.haomeiwen.com/subject/fitggctx.html