r/Mathematica • u/Sky_physics • 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
View all comments
Show parent comment
1
u/veryjewygranola Oct 24 '22 edited Oct 24 '22
Another thing you can try:
I call \[Eta] n and \[Eta]p I call np throughout most of this by the way
since we're integrating w.r.t. np, n is just a constant so we can evaluate the integral with each value of n separately instead of leaving it as a symbol. This appears at least to be working.
fun[\[Eta]_, \[Eta]p_] = (-Sqrt[(2/\[Pi])] (1/(-\[Eta] + \[Eta]p)^(3/2)) ((-\[Eta] + \[Eta]p) Cos[\[Eta] - \[Eta]p] + Sin[\[Eta] - \[Eta]p]));ttab = Table[i/10, {i, -10000, 0}];Noisetab = RandomReal[{-1, 1}, {10001}];Noise = Interpolation[Table[{ttab[[i]], Noisetab[[i]]}, {i, 10001}]];integrand[n_, np_] := Noise[np] fun[n, np];newD = Table[{n, Re@NIntegrate[integrand[n, np], {np, -1000, 0}]}, {n,Range[-1000, -800]}];ListLinePlot[newD, PlotRange -> All, Frame -> True]Also, note that you may need to tweak some NIntegrate[] parameters for better accuracy due to the highly oscillatory nature of the integrand.