如何检查表达式是否包含复杂表达式?

编程入门 行业动态 更新时间:2024-10-21 07:34:03
本文介绍了如何检查表达式是否包含复杂表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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 *)

更多推荐

如何检查表达式是否包含复杂表达式?

本文发布于:2023-11-28 15:30:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642963.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!