如何检查表达式是否包含复杂表达式? [英] How to check if expression contains a Complex expression?

查看:62
本文介绍了如何检查表达式是否包含复杂表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以检查一个表达式是否包含复数表达式/虚数?

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.

我在笔记本上张贴了一些示例: http://www.eacousineau.com/download/complex-test.nb

I posted some examples into a notebook: http://www.eacousineau.com/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 *)

这篇关于如何检查表达式是否包含复杂表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆