获取 x 作为 mathematica 中 Re[x] 的结果
我正在尝试获取涉及未定义变量(假设x
)的操作结果的实部。
如果我知道 x
永远不会是复数,那么当我执行 Re[x]
时,如何让 Mathematica 返回 x
?我认为这涉及告诉 Mathematica x 是实数,但我不知道如何。
就我而言,我想要实部的表达式比简单变量更复杂,但概念保持不变。
一些例子:
INPUT OUTPUT DESIRED RESULT
----- ------ --------------
Re[x] Re[x] x
Re[1] 1 1
Re[Sin[x]] Re[Sin[x]] Sin[x]
Re[1+x+I] 1 + Re[x] 1+x
Re[1 + x*I] 1-Im[x] 1
I'm trying to obtain the real part of the result of an operation which involves an undefined variable (let's say x
).
How can I have Mathematica return x
when I execute Re[x]
if I know that x
will never be a complex number? I think this involves telling Mathematica that x
is a real, but I don't know how.
In my case the expression for which I want the real part is more complicated than a simple variable, but the concept will remain the same.
Some examples:
INPUT OUTPUT DESIRED RESULT
----- ------ --------------
Re[x] Re[x] x
Re[1] 1 1
Re[Sin[x]] Re[Sin[x]] Sin[x]
Re[1+x+I] 1 + Re[x] 1+x
Re[1 + x*I] 1-Im[x] 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
例如,您可以使用输入
Simplify[Re[x], x \[Element] Reals]
,它将给出x
作为输出。You can use for example the input
Simplify[Re[x], x \[Element] Reals]
which will givex
as output.使用
ComplexExpand
。除非您另有说明,否则它假定变量是真实的。例如:Use
ComplexExpand
. It assumes that the variables are real unless you indicate otherwise. For example:还有两种可能性:
都返回
x
。Two more possibilities:
Both return
x
.有时为符号定义
UpValues
很有用。这远非稳健,但它仍然可以处理许多情况。Re[Sin[x]]
不会按照您的意愿进行计算,但FullSimplify
使用的转换之一确实将其置于触发的形式回复[x]
:It can at times be useful to define
UpValues
for a symbol. This is far from robust, but it nevertheless can handle a number of cases.Re[Sin[x]]
does not evaluate as you desire, but one of the transformations used byFullSimplify
does place it in a form that triggersRe[x]
: