矩阵化为最简形--列向量的最大线性最大无关组--阶梯型矩阵--特征值和特征向量

1 将矩阵化为最简形

以下是将矩阵 ( 1 7 2 5 2 3 0 − 1 1 − 1 2 1 0 6 4 0 4 1 2 − 1 ) \begin{pmatrix} 1 & 7 & 2 & 5 & 2 \\ 3 & 0 & -1 & 1 & -1 \\ 2 & 1 & 0 & 6 & 4 \\ 0 & 4 & 1 & 2 & -1 \end{pmatrix} 13207014210151622141 化为最简形的 Python 代码,并以矩阵形式展示结果:

from sympy import Matrix

# Define the matrix A
A = Matrix([
    [1, 7, 2, 5, 2],
    [3, 0, -1, 1, -1],
    [2, 1, 0, 6, 4],
    [0, 4, 1, 2, -1]
])

# Compute the reduced row echelon form (rref)
rref_matrix, pivot_columns = A.rref()

# Display the result
print("The matrix in reduced row echelon form is:")
print(rref_matrix)

运行此代码将输出:

The matrix in reduced row echelon form is:
Matrix([
[1, 0, 0, 0, 3/2],
[0, 1, 0, 0,  -2],
[0, 0, 1, 0,   6],
[0, 0, 0, 1, 1/2]])

化为最简形后的矩阵表示为:

( 1 0 0 0 3 2 0 1 0 0 − 2 0 0 1 0 6 0 0 0 1 1 2 ) \begin{pmatrix} 1 & 0 & 0 & 0 & \frac{3}{2} \\ 0 & 1 & 0 & 0 & -2 \\ 0 & 0 & 1 & 0 & 6 \\ 0 & 0 & 0 & 1 & \frac{1}{2} \end{pmatrix} 1000010000100001232621

2 求矩阵列向量的最大线性最大无关组

对于矩阵 ( 1 7 2 5 2 3 0 − 1 1 − 1 2 1 0 6 4 0 4 1 2 − 1 ) \begin{pmatrix} 1 & 7 & 2 & 5 & 2 \\ 3 & 0 & -1 & 1 & -1 \\ 2 & 1 & 0 & 6 & 4 \\ 0 & 4 & 1 & 2 & -1 \end{pmatrix} 13207014210151622141

最大线性无关组的列索引是 ((0, 1, 2, 3)),即列向量:

( 1 3 2 0 ) , ( 7 0 1 4 ) , ( 2 − 1 0 1 ) , ( 5 1 6 2 ) \begin{pmatrix} 1 \\ 3 \\ 2 \\ 0 \end{pmatrix}, \begin{pmatrix} 7 \\ 0 \\ 1 \\ 4 \end{pmatrix}, \begin{pmatrix} 2 \\ -1 \\ 0 \\ 1 \end{pmatrix}, \begin{pmatrix} 5 \\ 1 \\ 6 \\ 2 \end{pmatrix} 1320 , 7014 , 2101 , 5162

将其余的列向量表示为最大无关组的线性组合:

第5列向量 ( 2 − 1 4 − 1 ) \begin{pmatrix} 2 \\ -1 \\ 4 \\ -1 \end{pmatrix} 2141 可以表示为:

( 2 − 1 4 − 1 ) = 3 2 ( 1 3 2 0 ) − 2 ( 7 0 1 4 ) + 6 ( 2 − 1 0 1 ) + 1 2 ( 5 1 6 2 ) \begin{pmatrix} 2 \\ -1 \\ 4 \\ -1 \end{pmatrix} = \frac{3}{2} \begin{pmatrix} 1 \\ 3 \\ 2 \\ 0 \end{pmatrix} - 2 \begin{pmatrix} 7 \\ 0 \\ 1 \\ 4 \end{pmatrix} + 6 \begin{pmatrix} 2 \\ -1 \\ 0 \\ 1 \end{pmatrix} + \frac{1}{2} \begin{pmatrix} 5 \\ 1 \\ 6 \\ 2 \end{pmatrix} 2141 =23 1320 2 7014 +6 2101 +21 5162

即:

( 2 − 1 4 − 1 ) = 3 2 v 1 − 2 v 2 + 6 v 3 + 1 2 v 4 \begin{pmatrix} 2 \\ -1 \\ 4 \\ -1 \end{pmatrix} = \frac{3}{2} \mathbf{v}_1 - 2 \mathbf{v}_2 + 6 \mathbf{v}_3 + \frac{1}{2} \mathbf{v}_4 2141 =23v12v2+6v3+21v4

其中 v 1 , v 2 , v 3 , v 4 \mathbf{v}_1, \mathbf{v}_2, \mathbf{v}_3, \mathbf{v}_4 v1,v2,v3,v4 分别是最大无关组的列向量。

# Define the matrix A
A = Matrix([
    [1, 7, 2, 5, 2],
    [3, 0, -1, 1, -1],
    [2, 1, 0, 6, 4],
    [0, 4, 1, 2, -1]
])

# Compute the reduced row echelon form
rref_matrix, pivot_columns = A.rref()

# Get the maximum linearly independent set of columns
max_independent_set = A[:, pivot_columns]

# Express the remaining columns as linear combinations of the independent set
expressions = {}
for i in range(A.shape[1]):
    if i not in pivot_columns:
        coeffs = rref_matrix[:, i]
        expression = {}
        for j, coeff in enumerate(coeffs):
            if coeff != 0:
                expression[pivot_columns[j]] = coeff
        expressions[i] = expression

pivot_columns, max_independent_set, expressions

3 给你一个增广矩阵,你帮我求出他的阶梯型矩阵(1,-1,3,-1,1;2,-1,-1,4,2;3,-2,2,3,3)最后一个列是增广列

以下是给定增广矩阵 ( 1 − 1 3 − 1 1 2 − 1 − 1 4 2 3 − 2 2 3 3 ) \begin{pmatrix} 1 & -1 & 3 & -1 & 1 \\ 2 & -1 & -1 & 4 & 2 \\ 3 & -2 & 2 & 3 & 3 \end{pmatrix} 123112312143123 的阶梯型矩阵:

( 1 0 − 4 5 1 0 1 − 7 6 0 0 0 0 0 0 ) \begin{pmatrix} 1 & 0 & -4 & 5 & 1 \\ 0 & 1 & -7 & 6 & 0 \\ 0 & 0 & 0 & 0 & 0 \end{pmatrix} 100010470560100

这个矩阵已经转换为阶梯型形式。

from sympy import Matrix

# Define the augmented matrix
augmented_matrix = Matrix([
    [1, -1, 3, -1, 1],
    [2, -1, -1, 4, 2],
    [3, -2, 2, 3, 3]
])

# Compute the row echelon form
echelon_matrix = augmented_matrix.rref()[0]

echelon_matrix

4 求特征值和特征向量

将该矩阵 ( − 1 1 1 0 1 4 0 4 1 ) \begin{pmatrix} -1 & 1 & 1 \\ 0 & 1 & 4 \\ 0 & 4 & 1 \end{pmatrix} 100114141 的特征值和对应的特征向量写成分数或无理数如下:

特征值:
− 1 , 5 , − 3 -1, 5, -3 1,5,3

对应的特征向量(按列排列):

  • 对应特征值 − 1 -1 1 的特征向量是:
    ( 1 0 0 ) \begin{pmatrix} 1 \\ 0 \\ 0 \end{pmatrix} 100

  • 对应特征值 5 5 5的特征向量是:
    ( 1 3 1 1 ) \begin{pmatrix} \frac{1}{3} \\ 1 \\ 1 \end{pmatrix} 3111

  • 对应特征值 − 3 -3 3的特征向量是:
    ( 0 − 1 1 ) \begin{pmatrix} 0 \\ -1 \\ 1 \end{pmatrix} 011

#写成分数或者无理数的形式
import numpy as np
from sympy import Matrix, Rational
##求矩阵特征值和特征向量
# Define the matrix
matrix = np.array([[2, 0, 0], [0, 3, 2], [0, 2, 3]])

# Compute the eigenvalues and eigenvectors using numpy
eigenvalues, eigenvectors = np.linalg.eig(matrix)

# Convert numpy arrays to sympy for exact computation
matrix_sympy = Matrix(matrix)
eigenvals = matrix_sympy.eigenvals()
eigenvecs = matrix_sympy.eigenvects()

# Print eigenvalues as fractions or irrational numbers
print("Eigenvalues:")
for val in eigenvals:
    print(Rational(val).limit_denominator())

# Print eigenvectors as fractions or irrational numbers
print("\nEigenvectors:")
for val, multiplicity, vecs in eigenvecs:
    for vec in vecs:
        print(f"Eigenvalue {Rational(val).limit_denominator()}:")
        print(vec)

不写成分数或者无理数形式

import numpy as np

# Define the matrix
matrix = np.array([[-1, 1, 1], [0, 1, 4], [0, 4, 1]])

# Compute the eigenvalues and eigenvectors
eigenvalues, eigenvectors = np.linalg.eig(matrix)

eigenvalues, eigenvectors

  • 14
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值