4

When integrate the indefinite integral Cos[nx]Cos[kx] about x, where both k and n are positive integer, the result is Pi when n equals to k and 0 when n is unequal to k. However, the code

sol = Integrate[Cos[n*x]*Cos[k*x], {x, -Pi, Pi}, 
  Assumptions -> n ∈ Integers && k ∈ Integers && n > 0 && k > 0]

gives the result (k Sin[π k + π n] - n Sin[π k + π n] + k Sin[π k - π n] + n Sin[π k - π n])/(k^2 - n^2). enter image description here

And then use the Simplify function,

Simplify[sol, Assumptions -> n ∈ Integers && k ∈ Integers && n > 0 && k > 0]

gives the result 0. Shouldn't that Integrate returns a Piecewise function like Piecewise[{{Pi, n == k}, {0, n != k}}] instead?

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
shelure21
  • 165
  • 5

1 Answers1

6

This is well know issue. One way to handle it is

Simplify[ sol, 
 Assumptions -> Element[n, Integers] && Element[k, Integers] && n > 0 && k > 0 && k != n]

(* 0 *)

And

Simplify[ Limit[sol, k -> n], 
 Assumptions -> Element[n, Integers] && Element[k, Integers] && n > 0 && k > 0 && k == n ]

(* Pi *)

See

should-integrate-detect-orthogonality-of-functions-in-the-integrand

And

What assumptions to use to check for orthogonality

And

should-integrate-have-given-zero-for-this-integral

And

proper-way-to-simplify-integral-result-in-mathematica-given-integer-constraints

And

usage-of-assuming-for-integration

Nasser
  • 143,286
  • 11
  • 154
  • 359