获取 x 作为 mathematica 中 Re[x] 的结果

发布于 2024-12-25 02:11:48 字数 549 浏览 3 评论 0原文

我正在尝试获取涉及未定义变量(假设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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

遥远的她 2025-01-01 02:11:48

例如,您可以使用输入 Simplify[Re[x], x \[Element] Reals] ,它将给出 x 作为输出。

You can use for example the input Simplify[Re[x], x \[Element] Reals] which will give x as output.

浮生未歇 2025-01-01 02:11:48

使用ComplexExpand。除非您另有说明,否则它假定变量是真实的。例如:

In[76]:= ComplexExpand[Re[x]]
Out[76]= x

In[77]:= ComplexExpand[Re[Sin[x]]]
Out[77]= Sin[x]

In[78]:= ComplexExpand[Re[1+x+I]]
Out[78]= 1+x

Use ComplexExpand. It assumes that the variables are real unless you indicate otherwise. For example:

In[76]:= ComplexExpand[Re[x]]
Out[76]= x

In[77]:= ComplexExpand[Re[Sin[x]]]
Out[77]= Sin[x]

In[78]:= ComplexExpand[Re[1+x+I]]
Out[78]= 1+x
绅士风度i 2025-01-01 02:11:48

还有两种可能性:

Assuming[x \[Element] Reals, Refine[Re[x]]]

Refine[Re[x], x \[Element] Reals]

都返回x

Two more possibilities:

Assuming[x \[Element] Reals, Refine[Re[x]]]

Refine[Re[x], x \[Element] Reals]

Both return x.

坏尐絯℡ 2025-01-01 02:11:48

有时为符号定义 UpValues 很有用。这远非稳健,但它仍然可以处理许多情况。

Re[x] ^= x;
Im[x] ^= 0;

Re[x]
Re[1]
Re[1 + x + I] 
Re[1 + x*I]

x

1

1 + x

1

Re[Sin[x]] 不会按照您的意愿进行计算,但 FullSimplify 使用的转换之一确实将其置于触发的形式回复[x]

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[x] ^= x;
Im[x] ^= 0;

Re[x]
Re[1]
Re[1 + x + I] 
Re[1 + x*I]

x

1

1 + x

1

Re[Sin[x]] does not evaluate as you desire, but one of the transformations used by FullSimplify does place it in a form that triggers Re[x]:

Re[Sin[x]] // FullSimplify
Sin[x]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文