# Singular integral mathematica

A = Integrate[Sin[2 x] / (A1 - B1 Sin[2 x] + C1 Cos[x] - D1 Sin[x]), {x, 0, 2 Pi}]


The calculation is taking too much time; not returning any results. Any help?

• What are the values of A1, B1, C1, D1? Aug 21, 2015 at 7:39
• These will be functions, i need it to get it solved with A1,B1,C1 and D1. Aug 21, 2015 at 7:42
• Then you should not use NIntegrate. You can't numerically integrate a symbolic function, for what I hope are obvious reasons: what is Mathematica supposed to output for NIntegrate[f[x], {x, 0, 1}]? If they are to be functions, you should also make them functions by using C1[x] rather than just C1. Aug 21, 2015 at 7:43
• You are right. I am not doing NIntegrate, i am doing Integrate from {x,0,2Pi}. But mathematica can solve it? Aug 21, 2015 at 7:48
• You have to fix your nesting -- you don't have an equal number of parentheses. Aug 21, 2015 at 8:05

You can take the indefinite integral. Then you could try to use the fundamental theorem of calculus which means inserting the two boundary values for x into the indefinite integral and taking the difference. The result is the integral to be calculated in the OP if the indefinite intergral is a continuous function of x in the interval between 0 and 2 Pi. But continuity can only be checked if more information about the parameters A1 through D1 is given.

The indefinite integral is readily calculated by Mathematica:

Aindef =
Integrate[Sin[2 x]/(A1 - B1 Sin[2 x] + C1 Cos[x] - D1 Sin[x]), x]

(* Out[221]= (1/(2 B1))(-2 x +
RootSum[-I B1 + C1 #1 - I D1 #1 + 2 A1 #1^2 + C1 #1^3 + I D1 #1^3 +
I B1 #1^4 &, (2 C1 ArcTan[Sin[x]/(Cos[x] - #1)] -
2 I D1 ArcTan[Sin[x]/(Cos[x] - #1)] -
I C1 Log[1 - 2 Cos[x] #1 + #1^2] -
D1 Log[1 - 2 Cos[x] #1 + #1^2] +
4 A1 ArcTan[Sin[x]/(Cos[x] - #1)] #1 -
2 I A1 Log[1 - 2 Cos[x] #1 + #1^2] #1 +
2 C1 ArcTan[Sin[x]/(Cos[x] - #1)] #1^2 +
2 I D1 ArcTan[Sin[x]/(Cos[x] - #1)] #1^2 -
I C1 Log[1 - 2 Cos[x] #1 + #1^2] #1^2 +
D1 Log[1 - 2 Cos[x] #1 + #1^2] #1^2)/(C1 - I D1 + 4 A1 #1 +
3 C1 #1^2 + 3 I D1 #1^2 + 4 I B1 #1^3) &])
*)


Even in simple cases (e.g. A1=1, B1 = 1/2, C1 = D1 = 0) the indefinite integral is not contiuous.

EDIT #1

I would like to give a more detailed analysis of the problem than I did in my brief answer. Similar studies have been performed earlier. I shall provide the links soon. We shall see that this integral of a rather simple function with only poles in the complex plane of the integration variable contains quite a lot of interesting structure. And we can also grasp the difficulty - if not impossibility - of giving a symbolic answer in terms of mathematical constants.

First of all let the integrand be defined as in the OP by

f = Sin[2 x]/(A1 - B1 Sin[2 x] + C1 Cos[x] - D1 Sin[x]);


The general indefinite integral - also called antiderivative - was already calculated in the answer. For the time being we adopt strategy A, which is defined as inserting the constants into the integrand first and then calculate the antiderivative. (Doing it the other way round, strategy B, leads to a different result. This point needs further study.) We shall examine some examples, and the main focus will be on the question of continuity of the antiderivative.

Example 1: special case

rep1 = {A1 -> 1, B1 -> 1/2, C1 -> 0, D1 -> 0}; (* define the constants *)
f1 = f /. rep1 (* complete definition of integrand, with constants fixed *);
Print["Integrand = ", f1];
f1i = Integrate[f1, x] (* antiderivative of the integrand *);
Print["Antiderivative = ", f1i];
(* fi1=Evaluate[fi/.rep1] this would be strategy B, not used here *)
f1n = NIntegrate[f1, {x, 0, 2 \[Pi]}]; (* numerical value of the integral *)
Print["Numerical value of integral = ", f1n, "\n"];
Plot[{f1, Re[f1i], 0.5 + Im[f1i]}, {x, 0, 2 \[Pi]},
PlotLabel ->
"Example 1: special case\nblue - integrand\nbrown - Re[antiderivative]\n\
green - Im[antiderivative]+0.5"]
(* 150915_plot_antiderivative_f1i_01.jpg *)


$\text {Integrand = }\frac{\sin (2 x)}{1-\frac{1}{2} \sin (2 x)}$

$\text{Antiderivative = }-2 \left(\text{x}+\frac{2 \tan ^{-1}\left(\frac{1-2 \tan (\text{x})}{\sqrt{3}}\right)}{\sqrt{3}}\right)$

$\text{Numerical value of integral = }1.94402$

First we see that the antiderivative f1i is real (the green curve of the imaginary part was shifted upwards in oder to be seen at all). The function is discontinuous in two points where it has jumps. We can easily guess that they are located at [Pi]/2 and 3[Pi]/2 respectively. Their magnitude is given by

j1 = Limit[f1i, x -> \[Pi]/2, Direction -> -1] -
Limit[f1i, x -> \[Pi]/2, Direction -> +1] // Simplify

(*
Out[2425]= -((4 \[Pi])/Sqrt[3])
*)

j2 = Limit[f1i, x -> 3 \[Pi]/2, Direction -> -1] -
Limit[f1i, x -> 3 \[Pi]/2, Direction -> +1] // Simplify

(*
Out[2426]= -((4 \[Pi])/Sqrt[3])
*)


We can correct the curve by the jumps in their respective regions. But it is simpler to plot f1i together with f1i - j1 and f1i - j1 - j2.

Plot[{Re[f1i], Re[f1i - j1], Re[f1i - j1 - j2]}, {x, 0, 2 \[Pi]},
PlotLabel ->
"Example 1: special case\nblue - antiderivative f1i\nbrown - f1i + j1\n\
green - f1i + j1 + j2"]
(* 150915_plot_antiderivative_f1i_02.jpg *)


We get a continous curve consisting of three parts. For this continuuous curve we can apply the fundamental theorem of calculus and obtain

A = (f1i /. x -> 2 \[Pi] ) - (f1i /. x -> 0 ) - j1 - j2 // Simplify

(*
Out[2446]= (-4 + 8/Sqrt[3]) \[Pi]
*)
% // N

(* Out[2447]= 1.94402 *)


Which conincides with the numerical value of the integral given above.

This calculation would have to be done by Mathematica in order to give the nice symbolic result for the definite integral.

In general, calculating a (1-dimensinal) definite integral consists of these tasks

(i) find the antiderivate (defined up to a constant, of course) (ii) find the location of disconinuities (iii) calculate the magnitude of the jumps (vi) correct the original function (v) apply the fundamental theorem of calculus to the corrected antidrivative

Example 2: random constants

Here we turn to a more general form of the integrand, and we will see that the antiderivative is discontinuous in general and can have a complicated jump structure. We refrain from executing even step (ii) to the end.

We set A1->2 in order to avoid poles on the real axis. The other three constants will be taken as random variables defined as

r := Rationalize[RandomReal[{-1, 1}], 1/50]

rep2 = {A1 -> 2, B1 -> r, C1 -> r, D1 -> r}; (* define the constants *)
f2 = f /. rep2 (* complete definition of integrand, with constants fixed *);
Print["Integrand = ", f2];
f2i = Integrate[f2, x] (* antiderivative of the integrand *);
xPrint["Antiderivative = ", f2i];
(* f2ia=fi/.rep2; strategy B, not used here *)
f2n = NIntegrate[f2, {x, 0, 2 \[Pi]}];
Print["Numerical value of integral = ", f2n, "\n"];
cc = "{A1,B1,C1,D1} = " <> ToString[{A1, B1, C1, D1} /. rep2, InputForm];
Plot[{f2, Re[f2i], Im[f2i]}, {x, 0, 2 \[Pi]},
PlotLabel ->
"Example 2: random constants\n" <> cc <>
"\nblue - integrand\nbrown - Re[antiderivative]\ngreen - \
Im[antiderivative]", PlotRange -> All]


We skip the Printouts for simplicity and just show two curves.

It might be interesting to run example 2 several times to get more cases.

A1[x_] := 2*3
B1[x_] := 2*2
C1[x_] := 1/4
D1[x_] := 1/1000


you can use them with your own Function:

f[x_] := (Sin[2 x]/((A1[x] - B1[x] Sin[2 x] + C1[x] Cos[x] - D1[x] Sin[x])))


For a first overview we make a Plot:

Plot[f[x], {x, 0, 2 π}]


NIntegrate works quite well

NIntegrate[f[x], {x, 0, 2 \[Pi]}] // Timing


{0.007543, 0.540597}

As well Integrate

Integrate[f[x], x] // Timing

{0.079263, -(x/4) -
1/8 I RootSum[-4000 - (1 + 250 I) #1 -
12000 I #1^2 + (1 - 250 I) #1^3 +
4000 #1^4 &, ((500 - 2 I) ArcTan[Sin[x]/(
Cos[x] - #1)] - (1 + 250 I) Log[1 - 2 Cos[x] #1 + #1^2] +
24000 ArcTan[Sin[x]/(Cos[x] - #1)] #1 -
12000 I Log[1 - 2 Cos[x] #1 + #1^2] #1 + (500 + 2 I) ArcTan[
Sin[x]/(Cos[x] - #1)] #1^2 + (1 - 250 I) Log[
1 - 2 Cos[x] #1 + #1^2] #1^2)/((-1 - 250 I) -
24000 I #1 + (3 - 750 I) #1^2 + 16000 #1^3) &]}


For further information see;

NIntegrate Integration Strategies

Pure Functions

How to | Work with Variables and Functions