Proper way to simplify integral result in Mathematica given integer constraints

后端 未结 4 1669
余生分开走
余生分开走 2021-02-19 14:59

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,         


        
4条回答
  •  無奈伤痛
    2021-02-19 15:42

    Not always zero ...

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

    Visualizing those cases:

    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

    Compare with a zero result integral one:

    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

提交回复
热议问题