# NIntegrate with list gives weird results

Suppose I defined list or matrix with numericQ with some purpose,

AA[kx_?NumericQ, ky_?NumericQ] := {{kx^.5, 2 ky^2}, {kx^2, ky^2}},


and I want to numerically integrate this, such as,

NIntegrate[AA[qx, qy][[2,2]], {qx, 0, 10}, {qy, 0, 2}].


This manages to give right result with error,

Part::partd: Part specification AA[qx,qy][[2,2]] is longer than depth of object. >>

This is the first thing I can't understand because there seems to be no syntax error. Next, suppose I mistyped the above integration like,

NIntegrate[AA[qx, qy][[2]], {qx, 0, 10}, {qy, 0, 2}].


Even though AA[qx, qy][[2]] is List, NIntegrate gives number. That's the second I don't understand. Because of error I couldn't trust the result in research level.

re: why, since you specify _?NumericQ when NIntegrate makes its first attempt at symbolic evaluation AA returns unevaluated, thus the Part request fails.

here is another way to work around the problem:

AA[kx_?NumericQ, ky_?NumericQ, i_, j_] :=
{{kx^.5, 2 ky^2}, {kx^2, ky^2}}[[i, j]];
NIntegrate[AA[qx, qy, 2, 2], {qx, 0, 10}, {qy, 0, 2}]


26.6667

as to the even stranger seeming second result, the symbolic expression AA[qx,qy] has first level parts which are the arguments. AA[qx,qy][[2]] -> qy so then your integral is

  NIntegrate[qy, {qx, 0, 10}, {qy, 0, 2}]


20.

You can use Indexed. Indexed works like Part, but only extracts the part when the argument is a list. So:

NIntegrate[
Indexed[AA[qx,qy], {2,2}],
{qx, 0, 10}, {qy, 0, 2}
]


26.6667

• + .. note to document writers, why does neither Part nor Extract say "see also" Indexed ? Commented Nov 29, 2017 at 1:33

Try this:

AA[kx_, ky_] := {{kx^.5, 2 ky^2}, {kx^2, ky^2}};
NIntegrate[AA[qx, qy][[2, 2]], {qx, 0, 10}, {qy, 0, 2}]

(*  26.7  *)


Have fun!

• Yeah. I know the answer but what I don't get it is what 's wrong with NumericQ. At the first time, I think NumericQ and NIntegrate would work well but it did not. Commented Nov 28, 2017 at 15:43