给定场的线性独立

问题描述 投票:0回答:1

给定一组向量值函数,sympy 能否轻松提取一组线性无关函数?更一般地说, sympy 可以处理用户指定的字段以实现线性独立吗?我尝试过的所有方法(rref、column_space、rank)似乎都忽略了这种情况。

例如,

import sympy as s

x1, x2, x3 = s.symbols('x1 x2 x3')
M = s.Matrix([[x1, x2, 0, x1**2], [0, 0, x3, 0], [0, x2, 0, 0]])
M.columnspace()

M 有四列,它们与实数线性无关,但 M.columnspace() 永远不会产生超过 3 个独立列,因为它假设系数可以是 x1,x2,x3 中的函数。我们可以将系数限制为实数吗?

python sympy rank
1个回答
0
投票
 import sympy as s

 x1, x2, x3 = s.symbols('x1 x2 x3')
 M = s.Matrix([[x1, x2, 0, x1**2], [0, 0, x3, 0], [0, x2, 0, 0]])

 # Define real number coefficients
 a, b, c, d = s.symbols('a b c d', real=True)

 # Create the linear combination
 combination = M * s.Matrix([a, b, c, d])

 # Set up the system of equations
 equations = [s.Eq(expr, 0) for expr in combination]

 # Solve the system
 solution = s.solve(equations, (a, b, c, d))

 print(solution)

此脚本将返回使线性组合等于零向量的系数 a、b、c、d 的解。如果唯一解是{a: 0, b: 0, c: 0, d: 0},则在系数为实数的约束下,M 的列是线性独立的。

© www.soinside.com 2019 - 2024. All rights reserved.