# Two variables integrals: How to integrate with respect to one variable, then evaluate and plot the result with respect to the second variable?

I have started using Mathematica for a moment, but I'm now struggling to make some more advance calculations, for which I don't know how to overcome some difficulties. In fact, my wish is to evaluate an integral with respect to one variable and plot the result with respect to another variable. The problem i face here is that the integration cannot be obtained with a full explicit form since the integrand is a very complicated function. As a result, the code keeps running in indefinitely whenever i try to plot what should be the result of the integration. My code is the following, using Mathematica 9.

x = 10^-4; y = 10^4; n2 = 2; Nf = 100; alpha = 2;
W1 = Sqrt[n2^2 - z^2];
W2 = Sqrt[z^2 - n2^2];
Pr = ((alpha - 1) (x y)^(alpha - 1))/(y^(alpha - 1) - x^(alpha - 1));
D1 = Pr Exp[-z T] (Cos[T W1]/z^2 + 1/(z W1) Sin[T W1]);
D2 = Pr Exp[-z T] (Cosh[T W2]/z^2 + 1/(z W2) Sinh[T W2]);
XX = Integrate[D1, {z, x, n2}] + Integrate[D2, {z, n2, y}]
Plot[XX, {T, 0, 10}]


Try numerical integration

ClearAll[T, z, Pr, D1, D2, XX];
x = 10^-4; y = 10^4; n2 = 2; Nf = 100; alpha = 2;
W1 = Sqrt[n2^2 - z^2];
W2 = Sqrt[z^2 - n2^2];
Pr = ((alpha - 1) (x y)^(alpha - 1))/(y^(alpha - 1) - x^(alpha - 1));
D1[T_] := Pr*Exp[(-z)*T]*(Cos[T*W1]/z^2 + (1/(z*W1))*Sin[T*W1]);
D2[T_] := Pr*Exp[-z T] (Cosh[T W2]/z^2 + 1/(z W2) Sinh[T W2]);
XX[T_?NumericQ] := NIntegrate[D1[T], {z, x, n2}] + NIntegrate[D2[T], {z, n2, y}];

Plot[XX[T], {T, 0, 10}, AxesLabel -> {"T", "XX(T)"},
GridLines -> Automatic, GridLinesStyle -> LightGray]


• It works very well. Thanks a lot Commented Mar 16, 2020 at 7:52
• Please how can i improve it to obtain a 3D-plot, adding a new variable? Commented Mar 16, 2020 at 8:06
• @T.Arthur - Do not ask new questions in comments. Post a new question and include details on how the new variable is to be incorporated into the equations. Commented Mar 16, 2020 at 14:33
• Ok. I apologize. I didn't know Commented Mar 17, 2020 at 6:23
• @T.Arthur if you’ve found an answer to be to your liking, it is better for future users if you accept the answer by turning the check mark to green by clicking on it :) Commented Mar 17, 2020 at 13:03