在给定整数约束的 Mathematica 中简化积分结果的正确方法
计算以下积分应该是非零,并且 mathematica 正确地给出非零结果
Integrate[ Cos[ (Pi * x)/2 ]^2 * Cos[ (3*Pi*x)/2 ]^2, {x, -1, 1}]
但是,尝试更一般的积分:
FullSimplify[
Integrate[Cos[(Pi x)/2]^2 Cos[((2 n + 1) Pi x)/2] Cos[((2 m + 1) Pi x)/2],
{x, -1, 1}],
Element[{m, n}, Integers]]
产生零,这对于 m = n = 1 来说绝对不正确
我期望有一个条件表达式。在计算积分之前,是否可以“告诉”mathematica 我对 m 和 n 的约束,以便它正确处理特殊情况?
Evaluating the following integral should be non-zero, and mathematica correctly gives a non-zero result
Integrate[ Cos[ (Pi * x)/2 ]^2 * Cos[ (3*Pi*x)/2 ]^2, {x, -1, 1}]
However, attempting a more general integral:
FullSimplify[
Integrate[Cos[(Pi x)/2]^2 Cos[((2 n + 1) Pi x)/2] Cos[((2 m + 1) Pi x)/2],
{x, -1, 1}],
Element[{m, n}, Integers]]
yields zero, which is definitely not true for m = n = 1
I'd expect a conditional expression. Is it possible to "tell" mathematica about my constraints on m and n before the integral is evaluated so that it handles the special cases properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
虽然我迟到了,但到目前为止,还没有人给出完整的解决方案。
有时,在积分之前更好地理解被积函数是值得的。考虑一下,
它返回
每个项的形式为
Cos[q Pi x]
和整数q
。现在,在 -1 到 1(其中 q 是整数)上积分Cos[q Pi x]
时需要考虑两种情况:q == 0
和q != 0
。情况
q = 0
:这是 Mathematica 在一般结果中遗漏的特殊情况,因为它意味着一个常数被积函数。 (当我手动执行此操作时,我也经常会错过它,因此 Mathematica 不完全是罪魁祸首。)因此,在本例中,积分为 2。严格来说,这不是真的。当被告知在
-1
-1
上积分
,Mathematica 返回Cos[ q Pi x ]
时x < 10
,除非q == 0
。此时,该函数在严格意义上是未定义的,但 Limit[Sin[x]/x, q -> 0]==1。由于q == 0
处的奇点是可移除,因此积分当q -> 时,为
2
0 。所以,Mathematica 并没有错过它,它只是以一种无法立即识别的形式。情况
q != 0
:由于Cos[Pi x]
是周期性的,周期为2,因此Cos[q Pi x]的积分]
从x == -1
到x == 1
将始终超过q
个周期。换句话说,综合起来,这意味着
积分被积函数的扩展形式
使用它,我们可以通过它承认非积分解来 。为了解决这个问题,我们需要将条件减少到只有那些具有整体解决方案的条件,并且我们不妨简化一下:
\begin{Edit}
为了限制混乱,在内部
分段
具有以下结构:在使用
Apply
(@@
) 中,条件列表是第一个参数,默认参数是第二个参数。为了处理这个问题,我需要简化每个值的条件,因此我使用第二种简短形式Apply
(@@@
) 在条件列表上,以便对于每个值条件对我得到简化过程使用
Reduce
将条件限制为整数、LogicalExpand
帮助消除冗余,以及Simplify
限制项数。Reduce
内部使用 任意常量,C[1]
,它设置为C[1] == m
,因此我们将C[1]
设置回m< /code> 完成简化
\end{Edit}
给出了
完整的解决方案。
另一个编辑:我应该指出,1/2 和 1/4 情况都包含 3/ 中的
m
和n
值4 例。看起来 3/4 的情况可能是其他两个的交集,因此也是它们的总和。 (我还没有计算出来,但我强烈怀疑这是真的。)Piecewise
按顺序评估条件(我认为),因此不可能出现错误。再次编辑:
分段
对象的简化并没有达到应有的效率。问题在于替换规则C[1] -> 的位置。米。
Simplify
恰好在这个过程的后期使用它。但是,如果将其引入LogicalExpand
并将假设添加到Simplify
中,则会产生更清晰的结果
While I'm late to the party, no one has given a complete solution, thus far.
Sometimes, it pays to understand the integrand better before you integrate. Consider,
which returns
where each term has the form
Cos[q Pi x]
with integralq
. Now, there are two cases to consider when integratingCos[q Pi x]
over -1 to 1 (where q is integral):q == 0
andq != 0
.Case
q = 0
: This is a special case that Mathematica misses in the general result, as it implies a constant integrand. (I'll often miss it, also, when doing this by hand, so Mathematica isn't entirely to blame.) So, the integral is 2, in this case.Strictly speaking, this isn't true. When told to integrate
Cos[ q Pi x ]
over-1 < x < 1
, Mathematica returnswhich is
0
except whenq == 0
. At that point, the function is undefined in the strict sense, butLimit[Sin[x]/x, q -> 0] == 1
. As the singularity atq == 0
is removable, the integral is2
whenq -> 0
. So, Mathematica does not miss it, it is just in a form not immediately recognized.Case
q != 0
: SinceCos[Pi x]
is periodic with period 2, an integral ofCos[q Pi x]
fromx == -1
tox == 1
will always be overq
periods. In other words,Taken together, this means
Using this, we can integrate the expanded form of the integrand via
which admits non-integral solutions. To clean that up, we need to reduce the conditions to only those that have integral solutions, and we might as well simplify as we go:
\begin{Edit}
To limit confusion, internally
Piecewise
has the structureIn using
Apply
(@@
), the condition list is the first parameter and the default is the second. To process this, I need to simplify the condition for each value, so then I use the second short form ofApply
(@@@
) on the condition list so that for each value-condition pair I getThe simplification process uses
Reduce
to restrict the conditions to integers,LogicalExpand
to help eliminate redundancy, andSimplify
to limit the number of terms.Reduce
internally uses the arbitrary constant,C[1]
, which it sets asC[1] == m
, so we setC[1]
back tom
to complete the simplification\end{Edit}
which gives
as the complete solution.
Another Edit: I should point out that both the 1/2 and 1/4 cases include the values for
m
andn
in the 3/4 case. It appears that the 3/4 case may be the intersection of the other two, and, hence, their sum. (I have not done the calc out, but I strongly suspect it is true.)Piecewise
evaluates the conditions in order (I think), so there is no chance of getting this incorrect.Edit, again: The simplification of the
Piecewise
object is not as efficient as it could be. At issue is the placement of the replacement ruleC[1] -> m
. It happens to late in the process forSimplify
to make use of it. But, if it is brought inside theLogicalExpand
and assumptions are added toSimplify
then a much cleaner result is produce
并不总是零...
可视化这些情况:
与零结果积分一进行比较:
Not always zero ...
Visualizing those cases:
Compare with a zero result integral one:
如果您只需删除整个
FullSimplify
部分,mathematica 就会为您巧妙地进行集成。包含
m
和n
的条件是整数,最好使用Integrate
中的Asminations
选项。If you just drop the whole
FullSimplify
part, mathematica does the integration neatly for you.To include the condition that
m
andn
are integers, it's better to use theAssumptions
option inIntegrate
.让我们对两个整数使用一些结论性条件
m=n||m!=n
。本例的答案是
1/2
。对于另一种情况,答案是
0
。然而,我惊讶地发现,如果我们将这两个条件添加为“非此即彼”,Mathematica 在积分后会返回一零。我的意思是,在以下情况下,我只会得到零,但不会得到“1/2||0”。
顺便说一句,我们可以看到该积分变为
不确定
的唯一条件。输出在这里。
现在让我们看看
m
和n
的所有关系> 可能不得不使Integral
变坏!因此,这些是特殊情况,正如 Sjoerd 提到的那样,它们具有无限实例。
BR
Lets use some conclusive conditions about the two integers
m=n||m!=n
.The answer for this case is
1/2
. For the other case it isand the answer is
0
.However I am amazed to see that if we add this two conditions as an "either or stuff", Mathematica returns one zero after integration. I mean in case of the following I am getting only zero but not ``1/2||0`.
By the way we can see the conditions exclusively where this integral becomes
Indeterminate
.The output is here.
Now lets see all the relations
m
andn
can have to make theIntegral
bad!So these are the special cases which as Sjoerd mentioned are having infinite instances.
BR