在给定整数约束的Mathematica中简化积分结果的正确方法

时间:2011-10-12 17:03:31

标签: wolfram-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的约束,以便它能正确处理特殊情况?

4 个答案:

答案 0 :(得分:11)

虽然我迟到了,但到目前为止还没有人给出完整的解决方案。

有时,在整合之前更好地理解被积函数是值得的。考虑,

ef = TrigReduce[
    Cos[(Pi x)/2]^2 Cos[((2 n + 1) Pi x)/2] Cos[((2 m + 1) Pi x)/2]]/.
  Cos[a_] :> Cos[ Simplify[a, Element[{m,n}, Integers] ] ]

返回

(2 Cos[(m - n) Pi x] + Cos[(1 + m - n) Pi x] + Cos[(1 - m + n) Pi x] + 
 Cos[(m + n) Pi x] + 2 Cos[(1 + m + n) Pi x] + Cos[(2 + m + n) Pi x] )/8

其中每个字词的格式为Cos[q Pi x],其中包含整数q。现在,将Cos[q Pi x]整合到-1到1(其中q为整数)时,需要考虑两种情况:q == 0q != 0

案例q = 0 :这是Mathematica在一般结果中遗漏的一个特例,因为它意味着一个不变的被积函数。 (我经常会错过它,当手工操作时,所以Mathematica并不是完全可以责备的。)所以,积分是2,在这种情况下。

严格地说,这不是真的。当被告知将Cos[ q Pi x ]整合到-1 < x < 1时,Mathematica会返回

2 Sin[ Pi q ]/( Pi q )

0q == 0除外。此时,严格意义上的函数未定义,但是Limit[Sin[x]/x, q -> 0] == 1。由于q == 0处的奇点为removable,因此2时积分为q -> 0。因此,Mathematica不会错过它,它只是一种不能立即识别的形式。

案例q != 0 :由于Cos[Pi x]是周期性的第2期,因此从Cos[q Pi x]x == -1的{​​{1}}的积分将会总是超过x == 1期。换句话说,

q

合在一起,这意味着

Integrate[ Cos[q Pi x], {x, -1, 1}, 
  Assumptions -> (Element[ q, Integers ] && q != 0) ] == 0

使用它,我们可以通过

集成扩展形式的被积函数
Integrate[ Cos[q Pi x], {x, -1, 1}, Assumptions -> Element[ q, Integers ] ] == 
Piecewise[{{ q == 0, 2 }, { 0, q!=0 }}]

承认非完整的解决方案。为了清理它,我们需要将条件减少到只有那些具有完整解决方案的条件,我们可以简化:{/ p>

intef = ef /. Cos[q_ Pi x] :> Piecewise[{{2, q == 0}, {0, q != 0}}] // 
 PiecewiseExpand 

<强> \开始{编辑}

为了限制混淆,内部(Piecewise[{#1, LogicalExpand[Reduce[#2 , {m, n}, Integers]] // Simplify[#] &} & @@@ #1, #2] & @@ intef) /. C[1] -> m 具有结构

Piecewise

在使用{ { { value, condition } .. }, default } Apply)时,条件列表是第一个参数,默认值是第二个参数。为了处理这个,我需要简化每个值的条件,然后我在条件列表上使用@@@@@)的第二个简短形式,以便对于每个值条件对,我得到< / p>

Apply

简化过程使用{ value, simplified condition } 将条件限制为整数,Reduce以帮助消除冗余,LogicalExpand限制术语数量。 Simplify在内部使用arbitrary constantReduce,它设置为C[1],因此我们将C[1] == m设置回C[1]以完成简化< / p>

<强> \ {结束编辑}

给出了

m

作为完整的解决方案。

另一个编辑:我应该指出1/2和1/4案例都包含3/4案例中Piecewise[{ {3/4, (1 + n == 0 || n == 0) && (1 + m == 0 || m == 0)}, {1/2, Element[m, Integers] && (n == m || (1 + m + n == 0 && (m <= -2 || m >= 1)))}, {1/4, (n == 1 + m || (1 + n == m && (m <= -1 || m >= 1)) || (m + n == 0 && (m >= 1 || m <= 0)) || (2 + m + n == 0 && (m <= -1 || m >= 0))) && Element[m, Integers]}, {0, True} } m的值。似乎3/4的情况可能是另外两个的交集,因此,它们的总和。 (我没有完成计算,但我强烈怀疑它是真的。)n按顺序评估条件(我认为),所以没有机会弄错。

再次编辑Piecewise对象的简化效率不高。问题在于替换规则Piecewise的位置。它发生在C[1] -> m使用它的过程的后期。但是,如果它被带入Simplify并且假设被添加到LogicalExpand

Simplify

然后产生更清洁的结果

(Piecewise[{#1, 
    LogicalExpand[Reduce[#2 , {m, n}, Integers] /. C[1] -> m] // 
     Simplify[#, {m, n} \[Element] Integers] &} & @@@ #1, #2] & @@ intef)

答案 1 :(得分:5)

并非总是零......

k = Integrate[
         Cos[(Pi x)/2]^2 Cos[((2 (n) + 1) Pi x)/2] Cos[((2 m + 1) Pi x)/ 2], 
         {x, -1, 1}, Assumptions -> Element[{m, n}, Integers]];

(*Let's find the zeroes of the denominator *)

d = Denominator[k];
s = Solve[d == 0, {m, n}]

(*The above integral is indeterminate at those zeroes, so let's compute 
  the integral again there (a Limit[] could also do the work) *)

denZ = Integrate[
          Cos[(Pi x)/2]^2 Cos[((2 (n) + 1) Pi x)/2] Cos[((2 m + 1) Pi x)/ 2] /.s, 
          {x, -1, 1}, Assumptions -> Element[{m, n}, Integers]];

(* All possible results are generated with m=1 *)

denZ /. m -> 1

(*
{1/4, 1/2, 1/4, 1/4, 1/2, 1/4}
*)

可视化这些案例:

Plot[Cos[(Pi x)/2]^2 Cos[((2 (n) + 1) Pi x)/2] Cos[((2 m + 1) Pi x)/2] 
     /. s /. m -> 1, {x, -1, 1}]

enter image description here

与零结果积分比较:

Plot[Cos[(Pi x)/2]^2 Cos[((2 (n) + 1) Pi x)/2] Cos[((2 m + 1) Pi x)/ 2] 
     /. {m -> 1, n -> 4}, {x, -1, 1}]

enter image description here

答案 2 :(得分:4)

如果您放弃整个FullSimplify部分,mathematica会为您整齐地进行整合。

Integrate[
 Cos[(Pi x)/2]^2 Cos[((2 n + 1) Pi x)/2] Cos[((2 m + 1) Pi x)/
    2], {x, -1, 1}]

enter image description here

要包含mn为整数的条件,最好使用Assumptions中的Integrate选项。

Integrate[
 Cos[(Pi x)/2]^2 Cos[((2 n + 1) Pi x)/2] Cos[((2 m + 1) Pi x)/
    2], {x, -1, 1}, Assumptions -> Element[{m, n}, Integers]]

enter image description here

答案 3 :(得分:2)

让我们对两个整数m=n||m!=n使用一些确凿的条件。

Assuming[{(n \[Element] Integers && m \[Element] Integers && m == n)},
Integrate[Cos[(Pi x)/2]^2 Cos[((2 n + 1) Pi x)/2] Cos[((2 m + 1) Pi x)/2],
{x, -1, 1}]]

此案例的答案是1/2。对于另一种情况,它是

Assuming[{(n \[Element] Integers && m \[Element] Integers && m != n)},
Integrate[
Cos[(Pi x)/2]^2 Cos[((2 n + 1) Pi x)/2] Cos[((2 m + 1) Pi x)/
 2], {x, -1, 1}]]

,答案是0

但令我惊讶的是,如果我们将这两个条件添加为“或者其他”,Mathematica会在积分后返回零。我的意思是在以下情况下我只得到零,但不是“1/2 || 0”。

Assuming[{(n \[Element] Integers && m \[Element] Integers && 
 m == n) || (n \[Element] Integers && m \[Element] Integers && 
 m != n)}, 
Integrate[
Cos[(Pi x)/2]^2 Cos[((2 n + 1) Pi x)/2] Cos[((2 m + 1) Pi x)/
 2], {x, -1, 1}]]

顺便说一下,我们可以看到这个积分变为Indeterminate的条件。

res = Integrate[
Cos[(Pi x)/2]^2 Cos[((2 n + 1) Pi x)/2] Cos[((2 m + 1) Pi x)/
  2], {x, -1, 1}] // Simplify

输出在这里。

enter image description here

现在让我们看看所有关系mn可能导致Integral坏了!

BadPart = (res*4 Pi);
Flatten@(Solve[(Denominator[#] == 0), m] & /@ 
 Table[BadPart[[i]], {i, 1, Length@BadPart}] /. 
Rule -> Equal) // TableForm

enter image description here

所以这些是Sjoerd提到的具有无限实例的特殊情况。

BR