Skip to content

线性方程模块 #1

Description

@half-lang

class GESolver
GESolver可以对给定的矩阵实行高斯消元法,使之变为阶梯型

Source: lam/linequ/guasselimination.py

GESolver(mat: MutableDenseMatrix)
用给定的矩阵mat构造一个求解器

Parameter

mat: MutableDenseMatrix
properties
mat: MutableDenseMatrix 存储构造函数输入的参数mat
course: List[MutableDenseMatrix] 存储阶梯化矩阵时每一步初等变换后的矩阵
get_course()
无返回,但执行化矩阵阶梯型的操作,并将化阶梯型矩阵的过程存储在求解器对象的course字段中。

class LinequSolver
LinequSolver用高斯消元法解形如AX = b的线性方程组,无论A是否是方阵都可以求解

Source: lam/linequ/linequsolver.py

LinequSolver(mat, vec, evaluate=True)
用系数矩阵mat和常数项b构造一个求解器

Parameter

mat: MutableDenseMatrix 线性方程的系数矩阵A
vec: MutableDenseMatrix 线性方程的常数项b,注意必须是竖向量
evaluate: bool 默认为True,在构造完成后立即执行求解函数get_course(),当值为False时则不执行求解
properties
mat: MutableDenseMatrix 存储构造函数输入的参数mat
Ab: MutableDenseMatrix 系数矩阵和常数项合在一起构成的扩增矩阵
elimination_course: List[MutableDenseMatrix] 存储用高斯消元法阶梯化Ab的每一步初等变换后的矩阵
solveset: tuple, sympy.sets.sets.EmptySet 方程的解
当方程AX = b只有唯一解时,solveset不含未知量;有无穷多个解时,会出现自由未知量,自由未知量默认为希腊字母;无解时,solveset是sympy.sets.sets.EmptySet类型,即它是空集

get_course()
无返回,如果构造对象时evaluate=False,则执行一次求解运算,并把结果和过程存储在对象的属性(properties)中。

解线性方程组格式示例
增广矩阵:C = (A, b)=
\left[\begin{matrix}1 & 1 & 1 & 1\1 & 1 & 1 & 1\2 & 1 & 3 & 2\end{matrix}\right]
\rightarrow
\left[\begin{matrix}1 & 1 & 1 & 1\0 & 0 & 0 & 0\2 & 1 & 3 & 2\end{matrix}\right]
\rightarrow
\left[\begin{matrix}1 & 1 & 1 & 1\0 & 0 & 0 & 0\0 & -1 & 1 & 0\end{matrix}\right]
\rightarrow
\left[\begin{matrix}1 & 1 & 1 & 1\0 & -1 & 1 & 0\0 & 0 & 0 & 0\end{matrix}\right]
$$

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions