Matlab绝对值平方

Matlab absolute value squared

我在 matlab 中找不到简化这个符号表达式的方法。 x将以实数计算

syms x
expr = abs(x)^2

我希望结果是

 expr = x^2

Matlab 给出

expr = abs(x)^2

你想要的解决方案只有在 x 是真实的情况下才有效,因此你需要告诉 MATLAB。

 assume(x, 'real')
 simplify(expr)

原因和@Ander Biguri说的一样。但是,在初始化 x 时,您也可以像这样告诉 MATLAB:

syms x real;    %Notice this
expr = abs(x)^2;
simplify(expr)