Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I defined

Integrate[Exp[p_. Cos[x_] + q_. Sin[x_]]*Sin[a_. Cos[x_] + b_. Sin[x_] - m_. x_],
{x_, 0, 2*Pi}] := Sqrt[-1]*Pi*((b - p)^2 + (a + q)^2)^(-m/2)*(((p^2 - q^2 + a^2 - b^2) 
+ Sqrt[-1]*(2*(p*q + a*b)))^(m/2)*BesselI[m, Sqrt[(p^2 + q^2 - a^2 - b^2) -     
Sqrt[-1]*(2 (a*p + b*q))]] - ((p^2 - q^2 + a^2 - b^2) -
Sqrt[-1]*(2 (p*q + a*b)))^(m/2)*BesselI[m, Sqrt[(p^2 + q^2 - a^2 - b^2) +       
Sqrt[-1]*(2 (a*p + b*q))]])

In accordance with the examples given in the mathematica documentation. However, the integral only evaluates for the exact symbolic values p,q,a,b,m. If I try to evaluate any other form of the integral, e.g.

Integrate[Exp[Cos[x]+Sin[x]]*Sin[Sin[x]+Cos[x]-x],{x,0,2*Pi}]

Mathematica is unable to evaluate the integral. Why doesn't the integral, the way I've defined it, evaluate for any given values of p,q,a,b,m?

share|improve this question
    
Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 3 hours ago
    
Related: (6169), (19534) – Michael E2 3 hours ago
2  
BTW, what examples are given in the documentation? (Where are they?) – Michael E2 3 hours ago

One problem is that Exp[y] evaluates to Power[E, y], so that the integral does not match the (held) pattern with Exp. Another is that other functions sometimes evaluate to other forms, such as Sin:

Sin[Sin[x] + Cos[x] - x]
(* -Sin[x - Cos[x] - Sin[x]] *)

Here is a fix that works on the example. I added a constant factor c_ to take care of the -1 factoring out of Sin[], and changed -m_ to +m_, mutatis mutandis. Other examples may simplify in other ways, so some testing may be necessary to cover all possible use-cases.

Internal`InheritedBlock[{Integrate},
 Unprotect[Integrate];
 Integrate[
   c_. Power[E, p_. Cos[x_] + q_. Sin[x_]]*
    Sin[a_. Cos[x_] + b_. Sin[x_] + m_. x_], {x_, 0, 2*Pi}] := 
  c (Sqrt[-1]*
     Pi*((b - p)^2 + (a + q)^2)^(m/2) * 
       (((p^2 - q^2 + a^2 - b^2) + Sqrt[-1]*(2*(p*q + a*b)))^(-m/2) * 
        BesselI[-m, Sqrt[(p^2 + q^2 - a^2 - b^2) - Sqrt[-1]*(2 (a*p + b*q))]] - 
      ((p^2 - q^2 + a^2 - b^2) - Sqrt[-1]*(2 (p*q + a*b)))^(-m/2)*
        BesselI[-m, Sqrt[(p^2 + q^2 - a^2 - b^2) + Sqrt[-1]*(2 (a*p + b*q))]]));
 Protect[Integrate];
 Integrate[Exp[Cos[x] + Sin[x]]*Sin[Sin[x] + Cos[x] - x], {x, 0, 2*Pi}]
 ]
(*
 -2 I π (-(1/2) (-1)^(3/4) BesselI[1, 2 (-1)^(1/4)] + 
    1/2 (-1)^(1/4) BesselI[1, 2 (-1)^(3/4)])
*)

See here for Internal`InheritedBlock.

share|improve this answer

Rather than define a function, you can define a replacement rule using Hold and RuleDelayed

rule = Hold[Integrate[
     Exp[p_. Cos[x_] + q_. Sin[x_]]*
      Sin[a_. Cos[x_] + b_. Sin[x_] - m_. x_], {x_, 0, 2 Pi}]] :>
   I*Pi*((b - p)^2 + (a + q)^2)^(-m/
       2)*(((p^2 - q^2 + a^2 - b^2) + I*(2*(p*q + a*b)))^(m/2)*
       BesselI[m, 
        Sqrt[(p^2 + q^2 - a^2 - b^2) - 
          I*(2 (a*p + b*q))]] - ((p^2 - q^2 + a^2 - b^2) - 
          I*(2 (p*q + a*b)))^(m/2)*
       BesselI[m, Sqrt[(p^2 + q^2 - a^2 - b^2) + I*(2 (a*p + b*q))]]);

Hold[Integrate[
    Exp[Cos[x] + Sin[x]]*Sin[Sin[x] + Cos[x] - x], {x, 0, 2 Pi}]] /. 
  rule // Simplify

(*  (-(-1)^(1/4))*Pi*
   (BesselI[1, 2*(-1)^(1/4)] + 
      I*BesselI[1, 2*(-1)^(3/4)])  *)

With inexact numerical values and using Chop to remove the negligible imaginary artifact

% // N // Chop

(*  3.09803  *)

Verifying with NIntegrate

NIntegrate[Exp[Cos[x] + Sin[x]]*Sin[Sin[x] + Cos[x] - x], {x, 0, 2 Pi}]

(*  3.09803  *)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.