I want to plot the fonction $$(5,5)\ni w\mapsto \lambda(w,k)$$ for $$k\in\{1,2,3,4\}$$ where $$\lambda(w,k)$$ is defined below on the penultimate line. The answering time looks infinite and I was not even able to draw the curve of $$w\mapsto A11[w,k]$$. I suspect that my code could be improved, and I would be grateful for any suggestion.

Here is the code:

setTimeout(function (
F[w_, k_, t_] =
1/(6 \[Pi])
Exp[I w Log[(1 + 1/3 Exp[I t])/(
1 - 1/3 Exp[I t])]]  Exp[-6 I k Exp[-I t]]/
Sqrt[ 1 - 1/9 Exp[2 I t]]  Exp[I t]

R[w_, k_] =
Integrate[F[w, k, t], {t, -\[Pi], \[Pi]},
Assumptions -> {w \[Element] Reals, k > 0}]

A11[w_, k_] =
1/(1 + Exp[-2 \[Pi] w ]) +
Exp[-\[Pi] w]/(1 + Exp[-2 \[Pi] w ]) Im[R[w, k]]

B1[w_, k_] =
Integrate[
Exp[s w - k Tan[s]] (2 Sinh[s w - k  Tan[s]])/Sin[s], {s,
0, \[Pi]/2}, Assumptions -> {w \[Element] Reals, k > 0}]

B3[w_, k_] =
Integrate[2 (Sinh[s w - k Tanh[s]])^2/Sinh[s] , {s, 0, \[Pi]/2}]

B4[w_, k_] =
Integrate[Cos[2 (s w - k Tanh[s])]/Sinh[s] , {s, \[Pi]/2, Infinity},
Assumptions -> {w \[Element] Reals, k > 0}]

A12[w_, k_] =
Exp[-\[Pi]  w]/(
2 \[Pi]) (B1[w, k] - Log[Tanh[\[Pi]/4]] + B3[w, k] + B4[w, k])

\[Lambda][w_, k_] =
1/2 (A11[w, k] +
Sqrt[(A11[w, k])^2 (1 + Exp[-2 \[Pi]  w]) + 4 (A12[w, k])^2])


• What ranges do you make your plots in? Can you redefine your code to work with NIntegrate? Dec 4, 2020 at 14:15
• Do not include the option Assumptions more than once. Either combine the assumptions in a list: Assumptions -> {w \[Element] Reals, k > 0}; or as a logical combination: Assumptions -> w \[Element] Reals && k > 0 Dec 4, 2020 at 14:37
• @Bob Hanlon Thanks for correcting this. Dec 4, 2020 at 18:02
• This is not Mathematica code. Dec 5, 2020 at 16:48

One way to have faster plotting is:

1. To use NIntegrate in B1 with smaller precision and accuracy goals

2. Run B1 over a list of values for w and/or k

Clear[B1];
B1[w_, k_] :=
Integrate[
Exp[s w - k Tan[s]] (2 Sinh[s w - k Tan[s]])/Sin[s], {s,
0, \[Pi]/2}, Assumptions -> w \[Element] Reals,
Assumptions -> k > 0] /; k > 0;
B1[w_?NumericQ, k_?NumericQ] :=
NIntegrate[
Exp[s w - k Tan[s]] (2 Sinh[s w - k Tan[s]])/Sin[s], {s,
0, \[Pi]/2},
Method -> {"GlobalAdaptive", "SymbolicProcessing" -> 0},
PrecisionGoal -> 2, AccuracyGoal -> 3] /; k > 0;

AbsoluteTiming[
Block[{wPoints = Range[100], kPoints = Range[100]},
lsPoints =
Flatten[Table[{w, k, B1[w, k]}, {w, wPoints}, {k, kPoints}], 1];
]
]

ListPlot3D[Map[{#[[1]], #[[2]], Log[#[[3]]]} &, lsPoints],
PlotRange -> All]


• Thanks a lot for your detailed answer. In fact, the function $B1$ is part of a subsequent formula defining another function $F$: something like $F[w_,k_]=B1[w,k]+...$ and I have trouble to use NIntegrate in that situation. Dec 4, 2020 at 17:59
• @Beziin Please, give a fuller description and/or code in your post then! Dec 4, 2020 at 23:29
• I did that, thanks for your follow-up. Dec 5, 2020 at 14:18