# Is there any faster way to evaluate an integral?

I have this integral

  A=2
B=1
FullSimplify[ Integrate[
4 A Exp[-(s2 - s1)] Sin[n1a \[Pi] s1] Sin[n1b \[Pi] s1] Sin[
n2a \[Pi] s2] Sin[n2b \[Pi] s2], {s1, 0, 1}, {s2, s1, 1}],
Assumptions -> {n1a \[Element] Integers, n1b \[Element] Integers,
n2a \[Element] Integers, n2b \[Element] Integers}]


But it take forever to evaluate it. Does any one know what is the better way to approach? Am I doing something wrong?

• I'm updated the code see my answer.How overcome sigularity. Sep 27 '17 at 11:14

The better way to approach:

sol = Integrate[4 A Exp[-(s2 - s1)] Sin[n1a π s1] Sin[n1b π s1] Sin[
n2a π s2] Sin[n2b π s2], {s2, s1, 1}] // Expand

sol2 = Integrate[#, {s1, 0, 1}] & /@ (sol)

A = 2;
n1a = 2;
n1b = 3;
n2a = 3;
n2b = 5;
sol2// Re // N
(* -0.148968 *)


Numerically:

int[A_, n1a_, n1b_, n2a_, n2b_] := NIntegrate[4 A Exp[-(s2 - s1)]
Sin[n1a π s1] Sin[n1b π s1] Sin[
n2a π s2] Sin[n2b π s2], {s1, 0, 1}, {s2, s1, 1}, Method -> "LocalAdaptive"]

int[2, 2, 3, 3, 5]
(* -0.148968 *)


EDITED:

Maybe You can use a Limit function to overcome (1/0). I'm converted yours function to Exp because Limit work faster.

sol = Integrate[4 A Exp[-(s2 - s1)] Sin[n1a \[Pi] s1] Sin[n1b \[Pi] s1] Sin[n2a \[Pi] s2] Sin[n2b \[Pi] s2] // TrigToExp // Expand, {s2, s1,1}];
sol2 = Integrate[#, {s1, 0, 1}] & /@ (sol) // Simplify;

Limit[Limit[Limit[Limit[sol2 /. A -> 1, {n1a -> 1}], {n1b -> 1}], {n2a ->
4}], {n2b -> 2}] // AbsoluteTiming

(* {2.03222, {(16 I (-1 + E) \[Pi]^2 (4 + 80 \[Pi]^2 +
E (-3 - 40 \[Pi]^2 + 144 \[Pi]^4)))/(
E (I + 2 \[Pi]) (1 + 40 \[Pi]^2 + 144 \[Pi]^4)^2)}}*)


In Mathematica 11.2 Limit function was updated a works a 60 time faster,than older version.

  Limit[sol2 /. A -> 1, {n1a -> 1, n1b -> 1, n2a -> 4, n2b -> 2}] // AbsoluteTiming(*Only this code works in Mathematica 11.2 or above*)

(*{0.0312725, ((1 - E) ((2 I - 2 \[Pi])/(E (I - 2 \[Pi])^2) + (
2 I + 2 \[Pi])/(E (I + 2 \[Pi])^2) + (
E^(-I (-I + 6 \[Pi])) (-2 I + 6 \[Pi]))/(-I + 6 \[Pi])^2 - (
E^(I (I + 6 \[Pi])) (2 I + 6 \[Pi]))/(I + 6 \[Pi])^2 -
I (1/(I - 2 \[Pi])^2 + 1/(I + 2 \[Pi])^2 - 1/(-I + 6 \[Pi])^2 -
1/(I + 6 \[Pi])^2)))/(4 (I + 2 \[Pi]))}*)

• Thank you so much. Another Question. I have many of these integrals and I eventually want to construct a function 0f n1a, n1b, n2a, n2b from them. Thats why I need to use FullSimplify to get a shorter answer. Can you also tell me another way to simplify the answer which is faster? (I don't want them Numerically) Sep 26 '17 at 16:44
• Use FullSimplify[func, TimeConstraint -> 10], it's mean for how many seconds to try doing any particular transformation.Read this: mathematica.stackexchange.com/questions/96602/… Sep 26 '17 at 17:11
• Better hardware,faster answer, one of the possibilities. Sep 26 '17 at 17:15
• Iwanuik I have a 2.7 Ghz Mac Pro ,with 8 GB memory, which I thought should be fine. Thank you Mariusz for your time, I have another question which is more of a mathematic question. Do you know a way to fine the poles of the answer of this integral? Sep 26 '17 at 19:59
• You can ask here: math.stackexchange.com Sep 26 '17 at 22:03