我想显示一个矩阵,在 sympy 中进行矩阵计算后将提取的公因子放在矩阵外部。
我写了下面的代码。
from sympy import *
a = symbols("a")
b = symbols("b")
A = Matrix([exp(I*a),exp(I*a)*exp(I*b)])
print simplify(A)
Run Code Online (Sandbox Code Playgroud)
我得到了低于输出。
Matrix([
[ exp(I*a)],
[exp(I*(a + b))]])
Run Code Online (Sandbox Code Playgroud)
但是,我想低于输出。
exp(I*a)*Matrix([
[ 1],
[exp(I*b)]])
Run Code Online (Sandbox Code Playgroud)
我尝试了 collect(A,exp(I*a)) 并得到了跟随错误。
Traceback (most recent call last):
File "<ipython-input-65-834f4c326df4>", line 1, in <module>
runfile('C:/Anaconda2/Programs/test/untitled44.py', wdir='C:/Anaconda2/Programs/test')
File "C:\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile
execfile(filename, namespace)
File "C:\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 74, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Anaconda2/Programs/test/untitled44.py", line 14, in <module>
collect(A,exp(I*a))
File "C:\Anaconda2\lib\site-packages\sympy\simplify\simplify.py", line 451, in collect
if …Run Code Online (Sandbox Code Playgroud)