Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I tried to integrate the following integral using Integrate[Sin[x]Csc[4x],x] and I am getting a strange result. $$\frac{1}{8 \sqrt{2}}\left(-2 i \text{ArcTan}\left[\frac{\text{Cos}\left[\frac{x}{2}\right]-\left(-1+\sqrt{2}\right) \text{Sin}\left[\frac{x}{2}\right]}{\left(1+\sqrt{2}\right) \text{Cos}\left[\frac{x}{2}\right]-\text{Sin}\left[\frac{x}{2}\right]}\right]-2 i \text{ArcTan}\left[\frac{\text{Cos}\left[\frac{x}{2}\right]-\left(1+\sqrt{2}\right) \text{Sin}\left[\frac{x}{2}\right]}{\left(-1+\sqrt{2}\right) \text{Cos}\left[\frac{x}{2}\right]-\text{Sin}\left[\frac{x}{2}\right]}\right]+2 \sqrt{2} \text{Log}\left[\text{Cos}\left[\frac{x}{2}\right]-\text{Sin}\left[\frac{x}{2}\right]\right]-2 \sqrt{2} \text{Log}\left[\text{Cos}\left[\frac{x}{2}\right]+\text{Sin}\left[\frac{x}{2}\right]\right]+2 \text{Log}\left[\sqrt{2}+2 \text{Sin}[x]\right]-\text{Log}\left[2-\sqrt{2} \text{Cos}[x]-\sqrt{2} \text{Sin}[x]\right]-\text{Log}\left[2+\sqrt{2} \text{Cos}[x]-\sqrt{2} \text{Sin}[x]\right]\right) $$

While the answer is

(1/8) Log[Sin[x] - 1] + (1/4) Sqrt[2] ArcTanh[Sin[x] Sqrt[2]] - (1/8) Log[1 + Sin[x]] $$\frac{\text{ArcTanh}\left[\sqrt{2} \text{Sin}[x]\right]}{2 \sqrt{2}}+\frac{1}{8} \text{Log}[-1+\text{Sin}[x]]-\frac{1}{8} \text{Log}[1+\text{Sin}[x]] $$

Why am I getting this strange result? Are those two answers equivalent? How to avoid such strange results?

Sorry if the question is inappropriate!

share|improve this question
    
if you compare, say Integrate[Sin[x] Csc[4 x], {x, 0, 1/2}] and NIntegrate[Sin[x] Csc[4 x], {x, 0, 1/2}] they seem to agree which is a good sign. –  chris Dec 23 '12 at 20:55
    
I didn't check, but I'm willing to bet 2 dollars that they're equivalent. –  yohbs Dec 23 '12 at 20:59
    
@yohbs Why do you think so? –  belisarius Dec 23 '12 at 21:19
    
@belisarius I thought so because I thought that the OP was comparing two outputs of MMA. Now that I see this is not the case, I withdraw my bet like a coward. –  yohbs Dec 23 '12 at 22:02
1  
There is one more error in the coefficient before the atanh. Please try to be more careful –  belisarius Dec 23 '12 at 22:51

4 Answers 4

Just playing around, Mathematica gives the correct solution :

int2 = FullSimplify[Integrate[TrigExpand[Sin[x] Csc[4 x]], x]];

FullSimplify@D[TrigToExp[int2], x]
(* Csc[4 x] Sin[x] *)

The real part of the two solutions match but the imaginary parts do not :

check = 1/8 Log[Sin[x] - 1] - 1/8 Log[Sin[x] + 1] + Sqrt[2]/4 ArcTanh[Sqrt[2] Sin[x]];

FullSimplify@D[check - int2, x]
(* 0 *)

and

SeedRandom[6];
FullSimplify[check - int2 /. x -> RandomReal[]]
(* 2.77556*10^-17 + 0.670379 I *)

Plot[Im[int2 - check], {x, -2 \[Pi], 2 \[Pi]}, 
   Ticks -> {{#, #} & /@ Range[-2 \[Pi], 2 \[Pi], \[Pi]/2], Automatic}, 
   GridLines -> {Range[-2 \[Pi], 2 \[Pi], \[Pi]/4], None}]

Im

share|improve this answer

Taking derivatives of your "correct answer" and comparing with the integrand, shows they are not that equal:

Mathematica graphics

While taking derivatives of Mma's result gives:

Mathematica graphics

share|improve this answer
    
what does that mean?? Is my "correct answer" not correct? please check the link I added up. –  Santosh Linkha Dec 23 '12 at 22:18
    
@experimentX I think there is an 'Atanh[]` whose h is missing in your question –  belisarius Dec 23 '12 at 22:33
    
I am extremely sorry for my mistake in Question. –  Santosh Linkha Dec 23 '12 at 22:42

The answer looks correct by comparing it to Maple's 16 (latest version).

The function (the answer) gives complex values at different x. A plot of the real part is an exact match. For the complex part there is constant piecewise shift and the Abs of the solutions also agree up to piecewise constant so the answer seems to be correct. The solution are plotted for x=-10..10

Here is Maple result

Mathematica graphics

This answer was typed into Mathematica and compared it with Mathematica's Integrate answer:

maple=(1/4)Sqrt[2] ArcTanh[Sin[x] Sqrt[2]]-(1/8) Log[1 + Sin[x]] + (1/8) Log[Sin[x]- 1]
mma = Integrate[Sin[x] Csc[4 x], x];

plot the real part

Plot[Evaluate[Re[{maple, mma}]], {x, -10, 10},PlotLegends -> {"maple", "mma"}]

Mathematica graphics

Plot the complex part

Plot[Evaluate[Im[{maple, mma}]], {x, -10, 10},PlotLegends -> {"maple", "mma"}]

Mathematica graphics

plot the magnitude

Plot[Evaluate[Abs[{maple, mma}]], {x, -10, 10},PlotLegends -> {"maple", "mma"}]

Mathematica graphics

share|improve this answer

Why am I getting this strange result?

Mathematica's symbolic integration methods are more complicated that first-year calculus methods, and can turn out to involve complex-valued functions. See for instance How does Mathematica integrate?

Are those two answers equivalent?

  1. Yes-but. The term Log[-1+Sin[x]], which is equivalent to Log[1-Sin[x]] + Pi I, is an undefined real-valued function for almost all $x$ -- might want to use Log[1-Sin[x]] instead if you're looking for a standard real analysis function. The term is fine as a complex-valued function.

  2. Yes, they're equivalent. From calculus we know that over an interval over which a function is continuous, any two antiderivatives differ by a constant, which in fact may be a complex number. Over disjoint intervals, the constants may differ. Your function $\sin x \csc 4x$ is continuous over intervals of the form ${n\pi \over 4}<x<{(n+1)\pi\over4}$. If you examine b.gatessucks' and Nasser M. Abbasi's plots you can see that the answers differ by constant throughout each such interval. (In fact, your integrand has a removable discontinuity at $n\pi$ and so the constant does not change at those values.)

How to avoid such strange results?

  1. Learn to love them, then they won't be strange. ;-) Seriously, they usually work as is, although in this case, for instance, you have to use the real part to graph it.

  2. Try simplifying the real part, which will always be an antiderivative if the integrand is real:

    i = Integrate[Sin[x] Csc[4 x], x];
    FullSimplify[Re[i], x \[Element] Reals]
    (* 1/32 (-8 ArcTanh[Sin[x]] + Sqrt[2] (2 Log[(Sqrt[2] + 2 Sin[x])^2] + 
       Log[1/(4 (-2 + Cos[2 x] + 2 Sqrt[2] Sin[x])^2)]))*)
    
share|improve this answer
    
thanks for an instructive answer. Can your FullSimplify[Re[i], x \[Element] Reals] answer always be considered a good anti-derivative throughout all values of x. If so why does mathematica and maple not pick up this solution rather than the complex one above? –  chris Dec 24 '12 at 8:54
1  
You can assume Re[i] will always be a valid antiderivative if your integrand is real-valued. I do not know that FullSimplify will always give a result you seek, though it should always give a correct one. Many people are surprised when they first learn Sin[x]^2, -Cos[x]^2, and -Cos[2x]/2 are all antiderivatives of 2 Sin[x] Cos[x]. Even in a simple integral, one can't say definitively which is the best, and all are right. All one can expect is that Mathematica, Maple, etc. give correct answers, but not always the same answer. –  Michael E2 Dec 24 '12 at 17:40

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.