2
$\begingroup$

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}]

Please, i need anyone's help for more advances strategies to overcome this problem. Thanks in advance

$\endgroup$
4
$\begingroup$

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]

Mathematica graphics

$\endgroup$
5
  • $\begingroup$ It works very well. Thanks a lot $\endgroup$
    – T. Arthur
    Mar 16 '20 at 7:52
  • $\begingroup$ Please how can i improve it to obtain a 3D-plot, adding a new variable? $\endgroup$
    – T. Arthur
    Mar 16 '20 at 8:06
  • 1
    $\begingroup$ @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. $\endgroup$
    – Bob Hanlon
    Mar 16 '20 at 14:33
  • $\begingroup$ Ok. I apologize. I didn't know $\endgroup$
    – T. Arthur
    Mar 17 '20 at 6:23
  • $\begingroup$ @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 :) $\endgroup$ Mar 17 '20 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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