I would like to carry out a number of numerical integrals in the form of a table:
Iint[\[Theta]_, \[Theta]1_] =
Exp[-I n \[Theta]] Exp[
I n1 \[Theta]] (rx^2 (Cos[\[Theta]] - Cos[\[Theta]1])^2 +
ry^2 (Sin[\[Theta]] - Sin[\[Theta]1])^2)^m Sqrt[
rx^2 Sin[\[Theta]]^2 + ry^2 Cos[\[Theta]]^2] Sqrt[
rx^2 Sin[\[Theta]1]^2 +
ry^2 Cos[\[Theta]1]^2] (rx^2 Sin[\[Theta]] Sin[\[Theta]1] +
ry^2 Cos[\[Theta]] Cos[\[Theta]1]);
Table[NIntegrate[
Iint[\[Theta], \[Theta]1], {\[Theta], 0, 2 \[Pi]}, {\[Theta]1, 0,
2 \[Pi]}], {m, 1, 2}, {n, 0, 1}, {n1, 0, 1}]
I know that some of these integrals vanish. When Mathematica does these particular numerical integrals, I get the expected errors regarding convergence being too slow and the code takes a lot longer to run than the non-zero integrals e.g. the following will run very quickly:
m = 1;
n = 0;
n1 = 0;
NIntegrate[
Iint[\[Theta], \[Theta]1], {\[Theta], 0, 2 \[Pi]}, {\[Theta]1, 0,
2 \[Pi]}]
My question is how do I run the table of numerical integrals quickly by telling Mathematica just to display zero if it's encountering convergence problems and the answer is going to be several orders of magnitude smaller than the others? Thanks in advance for any help.
Update (10/07/2020): The best I can come up with for speeding up the calculation when the integral is zero is to add on a bit to the integrand and then subtract off the corresponding amount after the integration:
Table[NIntegrate[
Iint[\[Theta], \[Theta]1] + 1, {\[Theta], 0, 2 \[Pi]}, {\[Theta]1,
0, 2 \[Pi]}] - 4 \[Pi]^2, {m, 1, 2}, {n, 0, 1}, {n1, 0, 1}]
Is there a more elegant way of doing this?
Quiet@Check[..., 0]
? around yourNIntegrate
$\endgroup$badmessages = {NIntegrate::inumr, NIntegrate::ncvb}; Quiet[Check[..., 0, badmessages], badmessages]
$\endgroup$