3
$\begingroup$

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?

$\endgroup$
10
  • $\begingroup$ 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. $\endgroup$
    – chris
    Commented Dec 23, 2012 at 20:55
  • $\begingroup$ I didn't check, but I'm willing to bet 2 dollars that they're equivalent. $\endgroup$
    – yohbs
    Commented Dec 23, 2012 at 20:59
  • $\begingroup$ @yohbs Why do you think so? $\endgroup$ Commented Dec 23, 2012 at 21:19
  • 1
    $\begingroup$ @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. $\endgroup$
    – yohbs
    Commented Dec 23, 2012 at 22:02
  • 1
    $\begingroup$ There is one more error in the coefficient before the atanh. Please try to be more careful $\endgroup$ Commented Dec 23, 2012 at 22:51

8 Answers 8

9
$\begingroup$

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)]))*)
    
$\endgroup$
8
  • $\begingroup$ 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? $\endgroup$
    – chris
    Commented Dec 24, 2012 at 8:54
  • 1
    $\begingroup$ 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. $\endgroup$
    – Michael E2
    Commented Dec 24, 2012 at 17:40
  • $\begingroup$ This is a very cool idea, but it does not work on on all antidirivatives like an antiderivative of (1 + x^2)^2/((1 - x^2)*(1 - 6*x^2 + x^4)^(3/4)) see github.com/stblake/algebraic_integration/issues/2 $\endgroup$ Commented Jun 2, 2022 at 12:09
  • $\begingroup$ @ВалерийЗаподовников First of all, the integrand is not real (everywhere). Second, I don't see what the desired result in the link is after a quick scan; I'm not sure it's worth reading carefully given my first observation. Third, computational simplification always has had, and likely always will have, limitations. What the user wants and what it gives are not always the same. $\endgroup$
    – Michael E2
    Commented Jun 2, 2022 at 15:15
  • 1
    $\begingroup$ @ВалерийЗаподовников It is an explicitly stated hypothesis of this answer, "the integrand is real." I think it is obvious that this is a necessary condition for the method shown. It is no surprise it does not work in your example. Your example has an antiderivative with complex values (for some x) no matter what the constant of integration is, even if all the formal occurrences of I are eliminated. Re[i] never has complex values and so cannot be a global antiderivative; therefore it cannot be equivalent to your desired formula. My method must fail in this case. $\endgroup$
    – Michael E2
    Commented Jun 3, 2022 at 17:24
8
$\begingroup$

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

$\endgroup$
0
4
$\begingroup$

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

$\endgroup$
3
  • $\begingroup$ what does that mean?? Is my "correct answer" not correct? please check the link I added up. $\endgroup$
    – S L
    Commented Dec 23, 2012 at 22:18
  • $\begingroup$ @experimentX I think there is an 'Atanh[]` whose h is missing in your question $\endgroup$ Commented Dec 23, 2012 at 22:33
  • $\begingroup$ I am extremely sorry for my mistake in Question. $\endgroup$
    – S L
    Commented Dec 23, 2012 at 22:42
4
$\begingroup$

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

$\endgroup$
0
2
$\begingroup$

Letting t = Tan[x/2], we can get a simpler result.

Integrate[Sin[x] Csc[4 x] D[2 ArcTan[t], t] /. x -> 2 ArcTan[t] // TrigExpand, t] /.
  t -> Tan[x/2] // FullSimplify // PowerExpand
FullSimplify[%, 0 < x < Pi/2]
D[%, x] // Simplify

$\frac{1}{8} \left(\sqrt{2} \left(\log \left(\sqrt{2} \sin (x)+1\right)-\log \left(\sqrt{2} \sin (x)-1\right)\right)-4 \tanh ^{-1}\left(\tan \left(\frac{x}{2}\right)\right)\right)$

$\frac{1}{4} \left(\sqrt{2} \tanh ^{-1}\left(\frac{\csc (x)}{\sqrt{2}}\right)-2 \tanh ^{-1}\left(\tan \left(\frac{x}{2}\right)\right)\right)$

$\sin (x) \csc (4 x)$

Alternatively, letting t = Sin[x]

Integrate[Sin[x] Csc[4 x] D[ArcSin[t], t] /. x -> ArcSin[t] // TrigExpand, t] /.
   t -> Sin[x] // FullSimplify

$\frac{1}{4} \left(\sqrt{2} \tanh ^{-1}\left(\sqrt{2} \sin (x)\right)-\tanh ^{-1}(\sin (x))\right)$

$\endgroup$
0
1
$\begingroup$

One can instantly recognize that the integrand can be expressed in terms of the Chebyshev polynomial of the second kind:

$$\int\frac{\sin x}{\sin 4x}\mathrm dx=\int\frac1{U_3(\cos x)}\mathrm dx$$

and thus, by letting $t=\cos x$,

FullSimplify[PowerExpand[(Integrate[-1/(Sqrt[1 - t^2] ChebyshevU[3, t]), t] /.
                          t -> Cos[x]) /. Sqrt[tmp_] :> Sqrt[TrigFactor[tmp]]]]
   (-Sqrt[2] Log[Sqrt[2] - 2 Cos[x]] + 2 Log[Cos[x]] - Sqrt[2] Log[Sqrt[2] + 2 Cos[x]] -
    2 Log[1 + Sin[x]] + Sqrt[2] (Log[2 - Sqrt[2] Cos[x] + Sqrt[2] Sin[x]] +
    Log[2 + Sqrt[2] Cos[x] + Sqrt[2] Sin[x]]))/8

Check by differentiating the result:

Simplify[D[%, x] == Sin[x] Csc[4 x]]
   True
$\endgroup$
1
$\begingroup$
expr0 = Sin[x] Csc[4 x];

expr1 = Integrate[expr0, x] // FullSimplify

(* (1/(8 Sqrt[2]))(-I π + 2 Sqrt[2] Log[Cos[x/2] - Sin[x/2]] - 
  2 Sqrt[2] Log[Cos[x/2] + Sin[x/2]] + 2 Log[Sqrt[2] + 2 Sin[x]] - 
  Log[2 - Sqrt[2] Cos[x] - Sqrt[2] Sin[x]] - 
  Log[2 + Sqrt[2] Cos[x] - Sqrt[2] Sin[x]]) *)

expr1 is an antiderivative of expr0

expr0 == D[expr1, x] // FullSimplify

(* True *)

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

expr2 is also ** an ** antiderivative of expr0

expr0 == D[expr2, x] // FullSimplify

(* True *)

Antiderivatives can differ by an arbitrary numeric constant (perhaps complex)

Assuming[Element[x, Reals], 
  Series[expr1 - expr2 // FullSimplify, {x, 0, 10}] // Simplify] // Normal

(* -(1/16) I (2 + Sqrt[2]) π *)

As expected, they differ by a numeric constant.

$\endgroup$
1
$\begingroup$

The Rubi package for Mathematica (available at http://www.apmaths.uwo.ca/~arich/) often gives antiderivatives in a nicer form:

Int[Sin[x] Csc[4 x], x]

$\frac{\tanh ^{-1}\left(\sqrt{2} \sin (x)\right)}{2 \sqrt{2}}-\frac{1}{4} \tanh ^{-1}(\sin (x))$

$\endgroup$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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