我一直在尝试使用命令A
在SymPy中找到符号矩阵A.nullspace
的零空间。现在,对于我输入的矩阵,计算没有完成(或者比我等待的时间更长)。
奇怪的是,Mathematica在几分之一秒内完成了这项计算。我将给出我使用的具体示例作为Mathematica输入代码(应该运行)
L = ({{0, -I a Sqrt[b] Conjugate[g] Conjugate[w], 0, I a Sqrt[b] g w,
2 g2 + 2 b g z Conjugate[g], 0, 0, 0,
2 g2}, {-I a Sqrt[b] g w, -g2 - b g z Conjugate[g] -
I (-dD + b d g Conjugate[g]), -I DD, 0, I a Sqrt[b] g w, 0, 0,
0, 0}, {0, -I DD, I dD - g2, 0, 0, I a Sqrt[b] g w, 0, 0,
0}, {I a Sqrt[b] Conjugate[g] Conjugate[w], 0,
0, -g2 - b g z Conjugate[g] -
I (dD - b d g Conjugate[g]), -I a Sqrt[b] Conjugate[
g] Conjugate[w], 0, I DD, 0, 0}, {0,
I a Sqrt[b] Conjugate[g] Conjugate[w],
0, -I a Sqrt[b] g w, -2 g2 - 2 b g z Conjugate[g], -I DD, 0,
I DD, 0}, {0, 0, I a Sqrt[b] Conjugate[g] Conjugate[w],
0, -I DD, -2 g2 + I b d g Conjugate[g] - b g z Conjugate[g], 0,
0, I DD}, {0, 0, 0, I DD, 0,
0, -I dD - g2, -I a Sqrt[b] Conjugate[g] Conjugate[w], 0}, {0, 0,
0, 0, I DD,
0, -I a Sqrt[b] g w, -2 g2 - I b d g Conjugate[g] -
b g z Conjugate[g], -I DD}, {0, 0, 0, 0, 0, I DD,
0, -I DD, -2 g2}});
MatrixForm[L]
NullSpace[L]
正如同一个矩阵所说,SymPy正在挣扎。这有什么理由吗?有什么其他方法可以在python中解决这个问题吗?
这是我的SymPy代码:
import numpy as np
import scipy
import sympy as sp
a = sp.symbols("a", real=True, positive=True)
b = sp.symbols("b", real=True, positive=True)
g = sp.symbols("g", real=True, positive=True)
g2 = sp.symbols("g2", real=True, positive=True)
DD = sp.symbols("DD", real=True, positive=True)
dD = sp.symbols("dD", real=True)
w = sp.symbols("w")
z = sp.symbols("z")
d = sp.symbols("d")
L = sp.Matrix([[0, -1j*a*sp.sqrt(b)*sp.conjugate(g)*sp.conjugate(w), 0, 1j*a*sp.sqrt(b)*g*w,
2*g2 + 2*b*g*z*sp.conjugate(g), 0, 0, 0,
2*g2], [-1j*a*sp.sqrt(b)*g*w, -g2 - b*g*z*sp.conjugate(g) -
1j*(-dD + b*d*g*sp.conjugate(g)), -1j*DD, 0, 1j*a*sp.sqrt(b)*g*w, 0, 0,
0, 0], [0, -1j*DD, 1j*dD - g2, 0, 0, 1j*a*sp.sqrt(b)*g*w, 0, 0,
0], [1j*a*sp.sqrt(b)*sp.conjugate(g)*sp.conjugate(w), 0,
0, -g2 - b*g*z*sp.conjugate(g) -
1j*(dD - b*d*g*sp.conjugate(g)), -1j*a*sp.sqrt(b)*sp.conjugate(
g)*sp.conjugate(w), 0, 1j*DD, 0, 0], [0,
1j*a*sp.sqrt(b)*sp.conjugate(g)*sp.conjugate(w),
0, -1j*a*sp.sqrt(b)*g*w, -2*g2 - 2*b*g*z*sp.conjugate(g), -1j*DD, 0,
1j*DD, 0], [0, 0, 1j*a*sp.sqrt(b)*sp.conjugate(g)*sp.conjugate(w),
0, -1j*DD, -2*g2 + 1j*b*d*g*sp.conjugate(g) - b*g*z*sp.conjugate(g), 0,
0, 1j*DD], [0, 0, 0, 1j*DD, 0,
0, -1j*dD - g2, -1j*a*sp.sqrt(b)*sp.conjugate(g)*sp.conjugate(w), 0], [0, 0,
0, 0, 1j*DD,
0, -1j*a*sp.sqrt(b)*g*w, -2*g2 - 1j*b*d*g*sp.conjugate(g) -
b*g*z*sp.conjugate(g), -1j*DD], [0, 0, 0, 0, 0, 1j*DD,
0, -1j*DD, -2*g2]]);
sp.pprint(L)
sp.pprint(L.nullspace())
根据评论,以下信息也可能是相关的:
a, b, g, g2, DD
dD
w, z, d
答案 0 :(得分:1)
同情的虚构单位是sympy.I
(不是1j
)。显然,1j
是可以接受的,但是,它被解释为数量,在符号计算中应该避免。
以下代码非常快速地给出了nullspace。请注意,我还提供了符号属性。这些通常有助于同情提供更快的答案
a = sp.symbols("a", positive = True)
b = sp.symbols("b", positive = True)
g = sp.symbols("g", positive = True)
w = sp.symbols("w")
z = sp.symbols("z")
g2 = sp.symbols("g2", positive = True)
DD = sp.symbols("DD", positive = True)
dD = sp.symbols("dD", real = True)
d = sp.symbols("d")
L = sp.Matrix([[0, -sp.I*a*sp.sqrt(b)*sp.conjugate(g)*sp.conjugate(w), 0, sp.I*a*sp.sqrt(b)*g*w,
2*g2 + 2*b*g*z*sp.conjugate(g), 0, 0, 0,
2*g2], [-sp.I*a*sp.sqrt(b)*g*w, -g2 - b*g*z*sp.conjugate(g) -
sp.I*(-dD + b*d*g*sp.conjugate(g)), -sp.I*DD, 0, sp.I*a*sp.sqrt(b)*g*w, 0, 0,
0, 0], [0, -sp.I*DD, sp.I*dD - g2, 0, 0, sp.I*a*sp.sqrt(b)*g*w, 0, 0,
0], [sp.I*a*sp.sqrt(b)*sp.conjugate(g)*sp.conjugate(w), 0,
0, -g2 - b*g*z*sp.conjugate(g) -
sp.I*(dD - b*d*g*sp.conjugate(g)), -sp.I*a*sp.sqrt(b)*sp.conjugate(
g)*sp.conjugate(w), 0, sp.I*DD, 0, 0], [0,
sp.I*a*sp.sqrt(b)*sp.conjugate(g)*sp.conjugate(w),
0, -sp.I*a*sp.sqrt(b)*g*w, -2*g2 - 2*b*g*z*sp.conjugate(g), -sp.I*DD, 0,
sp.I*DD, 0], [0, 0, sp.I*a*sp.sqrt(b)*sp.conjugate(g)*sp.conjugate(w),
0, -sp.I*DD, -2*g2 + sp.I*b*d*g*sp.conjugate(g) - b*g*z*sp.conjugate(g), 0,
0, sp.I*DD], [0, 0, 0, sp.I*DD, 0,
0, -sp.I*dD - g2, -sp.I*a*sp.sqrt(b)*sp.conjugate(g)*sp.conjugate(w), 0], [0, 0,
0, 0, sp.I*DD,
0, -sp.I*a*sp.sqrt(b)*g*w, -2*g2 - sp.I*b*d*g*sp.conjugate(g) -
b*g*z*sp.conjugate(g), -sp.I*DD], [0, 0, 0, 0, 0, sp.I*DD,
0, -sp.I*DD, -2*g2]]);
Ln = L.nullspace()