有没有一种方法可以检查一个表达式是否包含复数表达式/虚数?
Is there a way to check if an expression contains complex expressions / imaginary numbers?
文档说您不能检查表达式是否包含 I ,因为它是如何解释的.我也尝试过 ImaginaryQ [expr_]:= expr!=共轭[expr] 和 Simplify [expr] =!= Simplify [Conjugate [expr]] ,但确实如此无法产生准确的结果.我也尝试过使用MemberQ [expr,Complex],但这似乎也不起作用.
The documentation says that you can't check if an expression contains I because of how it is interpreted. I have also tried ImaginaryQ[expr_] := expr != Conjugate[expr] and Simplify[expr] =!= Simplify[Conjugate[expr]], but it does not yield accurate results. I have also tried to use MemberQ[expr, Complex], but that does not seem to work either.
我在笔记本上张贴了一些示例: www.eacousineau/download/complex-test.nb
I posted some examples into a notebook: www.eacousineau/download/complex-test.nb
推荐答案关于
ImaginaryQ[expr_] := ! FreeQ[expr, _Complex]在您的两个示例中使用它:
Using it on two of your examples:
imExpr = a Sin[a + 2 I]; ImaginaryQ@imExpr (* True *) reExpr = a Sin[a^2 + a]; ImaginaryQ@reExpr (* False *)更多推荐
如何检查表达式是否包含复杂表达式?
发布评论