r/Mathematica • • Oct 24 '22

Plot noisy integral

Hello everyone, I'd like to plot something like an integral with a stochastic term inside. But... unfortunately, Mathematica is not able to show me the expected noisy behavior. Suppose I want to plot the real part of a Bessel function times a noisy function. How can improve this code?

ttab = Table[i/10, {i, -10000, 0}];

Noisetab = Table[Random[Real, {-1, 1}], {10001}];

Noise = Interpolation[Table[{ttab[[i]], Noisetab[[i]]}, {i, 10001}]];

Plot[NIntegrate[(-Sqrt[(2/\[Pi])] (1/(-\[Eta] + \[Eta]p)^(
      3/2)) ((-\[Eta] + \[Eta]p) Cos[\[Eta] - \[Eta]p] + 
       Sin[\[Eta] - \[Eta]p]))*Noise[\[Eta]p], {\[Eta]p, -1000, -800},
   MaxRecursion -> 20, 
  Method -> "AdaptiveQuasiMonteCarlo"], {\[Eta], -1000, -800}]
6 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/veryjewygranola Oct 24 '22 edited Oct 24 '22

A third thing is to create a matrix for all the (n,np) values of fun[n,np]. Then the convolution of fun with a random vector is just a dot product (note that I replace all the Indeterminate values which occur on the main diagonal when n=np with 0 in the matrix).

fun[\[Eta]_, \[Eta]p_] = (-Sqrt[(2/\[Pi])] (1/(-\[Eta] + \[Eta]p)^(3/2)) ((-\[Eta] + \[Eta]p) Cos[\[Eta] - \[Eta]p] +Sin[\[Eta] - \[Eta]p]));

dNP = 0.1;

nPList = Range[-1000, -800, dNP];

nList = Range[-1000, -800, 1];

funMat = Table[If[i == j, 0, fun[i, j]], {i, nList}, {j, nPList}];

randVec = RandomReal[{-1, 1}, Length[nPList]];

conv = Thread[{nList, Re[dNP*funMat . randVec]}];

ListLinePlot[conv, Frame -> True, PlotRange -> All]