SymPy 没有简化矩阵与其共轭的乘法

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

我试图在 SymPy 中简化矩阵与其共轭的乘法,但简化并未按预期进行。这是我的代码:

import sympy as sp

# Define symbols
e = sp.Symbol('epsilon', real=True, domain=sp.Interval(0, 1, right_open=True))
i = sp.I
p = sp.Symbol('psi', real=True)

# Define the Jones matrix with additional assumption
J = sp.Matrix([
    [sp.sqrt(1 - e), -sp.sqrt(e) * sp.exp(i*p)],
    [sp.sqrt(e) * sp.exp(-i*p), sp.sqrt(1 - e)]
])

# Create the conjugate matrix
J_conj = sp.conjugate(J)

# Compute the Kronecker product
J_prod = sp.kronecker_product(J, J_conj)

我尝试使用

sp.simplify(J_prod)
J_prod
仍然一样。

J_prod

我想要

J_prod to
以这种形式呈现:

预计

J_prod

expected J_prod

sympy complex-numbers
1个回答
0
投票

显然,SymPy 有时难以处理复数。

我认为这可能有帮助:

J_prod_simple = sp.re(J_prod) + i * sp.im(J_prod)
© www.soinside.com 2019 - 2024. All rights reserved.