I have a double variable integral, so I can define a function which is the integration of the other variable, and finally, I integrate the other variable. here is the code:
y[x_?NumericQ] := NIntegrate[v^2 Exp[-x v^2], {v, 0, \[Infinity]}]
NIntegrate[y[x], {x, 20, 1000000}]
It takes a long time to run; also it gives two errors: NIntegrate::inumr and General::stop.
So, I thought doing the integration together at one time is faster, and indeed it is faster. Here is the code:
NIntegrate[v^2 Exp[-x v^2], {v, 0, \[Infinity]}, {x, 20, 1000000}]
It does not have errors and it is ten times faster. However, the final result is a different value. So, I have three questions:
1- Which one should I trust?
2- Why do they have different results?
3- How can I make the NIntegrate faster? The original problem is kind of complicated and since I am going to plot the contour plot of two variables, it takes an extremely long time to give me the plot. For each point, the second code takes about 0.2 seconds, which is for a ContourPlot is extremely high. I try to decrease the number of the points with PlotPoints, but still, it takes a long time and also I lose the quality of the graph. I tried to decrease the PrecisionGoal to 4 inside the NIntegate, it helps but not too much.
Thank you so much for your kind helps.
{int = Integrate[ v^2 Exp[-x v^2], {v, 0, \[Infinity]}, {x, 20, 1000000}], int // N}
to yield{((-1 + 100 Sqrt[5]) Sqrt[\[Pi]])/2000, 0.19728}
. For the original problem, try to do at least integration over one variable analytically. $\endgroup$x
range. (Thev
domain being infinite is transformed.) This performs betterNIntegrate[v^2 Exp[-x v^2] Dt[x, u] /. x -> Exp[u], {v, 0, \[Infinity]}, {u, Log[20], Log[1000000]}]
. If your actual problem is different, then the problem may lie in that difference. Usually, unhappy code is unhappy in its own way. $\endgroup$NIntegrate[v^2 Exp[-x v^2], {v, 0, \[Infinity]}, {x, 20, 1000000}, Exclusions -> {x v^2 == 30, x v^2 == 40}]
-- again focused the particular example. $\endgroup$MinPrecision -> 3
(for integrals of dimension $d$, the time increases by a factor of $n^d$). IncreaseWorkingPrecision
to 16, 24, 32. IncreasePrecisionGoal
6, 8, 10 (but as the goal reaches the working precision, you'll get errors because the difference is how much round-off/ill-conditioning the integration can tolerate). $\endgroup$Exclusions -> {x v^2 == 30, x v^2 == 40}
? TIA. $\endgroup$