1
$\begingroup$

Consider a function

f[x_, Z_, α_, mN_, q_, R_, S_] = 
  Assuming[mN > 0 && x > 0, 
   9*α*Z^2/(2*Pi)*((1 + (1 - x)^2)/x)*
    (q^2 - x^2 mN^2)/q^4*
    SphericalBesselJ[1, 
      R*q]^2/(R*q)^2*
    Exp[-q^2*S^2]];

It is defined in the domain $$ \text{max}[2\cdot 10^{-5}, x\cdot m_{N}]< q< q_{\text{max}} = 4.49/5, \quad 10^{-9}<x <q_{\text{max}}/m_{N} $$ I'm trying to obtain the interpolation of numerical integral $$ \int \limits_{q_{\text{min}}}^{q_{\text{max}}}dq^{2}f[x,42,1/137,100,q,5,0.726] $$ for the given value of x. Namely, I write

g1 = 
  Table[{x, 
    NIntegrate[
     f[x, q, 42, 1/137, 100, 5, 0.726]*2*q, {q, 
      Max[100*x, 2*10^-5], 4.49/5}]}, {x, 10^-9, 4.49/(5*100), 10^-4}];
g[x_] = Interpolation[g1 ][x]

Finally, I want to draw a plot of the function g[x]. I write

LogLogPlot[g[x], {x, 10^-9, 4.49/(5*100)}, PlotRange -> All]

And I see discontinuous plot. The point of discontinuity strongly depends on the table step size (I've tried from $10^{-7}$ to $10^{-2}$). From the other side, if I simply write

LogLogPlot[
 NIntegrate[
  Re[f[x, q, 42, 1/137, 100, 5, 0.726]]*2*q, {q, 
   Max[100*x, 2*10^-5], 4.49/5}], {x, 10^-9, 4.49/(5*100)}, 
 PlotRange -> All],

then the plot is smooth.

How to obtain correct interpolation?

The code sample is

 f[x_, Z_, α_, mN_, q_, R_, S_] = 
      Assuming[mN > 0 && x > 0, 
       9*α*Z^2/(2*Pi)*((1 + (1 - x)^2)/x)*
        (q^2 - x^2 mN^2)/q^4*
        SphericalBesselJ[1, 
          R*q]^2/(R*q)^2*
        Exp[-q^2*S^2]];

    g1 = 
      Table[{x, 
        NIntegrate[
         f[x, 42, 1/137, 100,q, 5, 0.726]*2*q, {q, 
          Max[100*x, 2*10^-5], 4.49/5}]}, {x, 10^-9, 4.49/(5*100), 10^-4}];
    g[x_] = Interpolation[g1 ][x]

    LogLogPlot[g[x], {x, 10^-9, 4.49/(5*100)}, PlotRange -> All]
$\endgroup$
  • $\begingroup$ What is PhotonDFx? Please provide sample code that can be evaluated from start to finish. $\endgroup$ – halirutan Feb 17 '18 at 2:11
  • $\begingroup$ @halirutan : sorry, this is g[x]. $\endgroup$ – John Taylor Feb 17 '18 at 9:01
  • $\begingroup$ f evaluates to zero: i.stack.imgur.com/qYsle.png -- In g1, you've substituted the argument q into the slot for Z. Perhaps that's a mistake? (If not, I get a constant 0. for the value of g, not a discontinuous function.) $\endgroup$ – Michael E2 Feb 17 '18 at 21:20
  • $\begingroup$ @MichaelE2 : you're right. Sorry for my mistakes... $\endgroup$ – John Taylor Feb 18 '18 at 0:37
  • $\begingroup$ Try Plot[g[x], {x, 10^-9, 4.49/(5*100)}, PlotRange -> All] and you'll see that the interpolation goes negative. That's why the log-log plot has a gap. Try InterpolationOrder -> 2 or InterpolationOrder -> 1. $\endgroup$ – Michael E2 Feb 18 '18 at 4:06
1
$\begingroup$

The problem is that the interpolation overshoots the x-axis, which makes the log-log plot undefined:

Plot[g[x], {x, 10^-9, 4.49/(5*100)},
 Epilog -> {Red, Point@g1}, PlotRange -> {{0, 0.0005}, All}]

Mathematica graphics

Lowering the interpolation order to 1 or 2 is one way that results in a positive interpolation. Another is to rescale the data:

gg[x_] = Interpolation[Log@g1][Log@x] // Exp

LogLogPlot[{g[x], gg[x]}, {x, 10^-9, 4.49/(5*100)},
 Epilog -> {Red, Point@Log@g1}, 
 PlotStyle -> {Thickness[0.012], Thickness[0.007]}, PlotRange -> All]

Mathematica graphics

$\endgroup$

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.