I have the following dummy Code
f[arg : {__?NumericQ}] := 2*arg;
g := f[{x, y}]
NIntegrate[g, {x, 0, 1}, {y, 0, 1}]
NIntegrate[f[{x, y}], {x, 0, 1}, {y, 0, 1}]
Both tries yield
NIntegrate::inum: Integrand f[{x,y}] is not numerical at {x,y} = {0.5,0.5}.
Despite
f[{x, y}] /. x -> 0.5 /. y -> 0.5
{1.,1.}
f[{0.5, 0.5}]
{1.,1.}
However, if I enter the function directly, I get the expected result
NIntegrate[2*{x, y}, {x, 0, 1}, {y, 0, 1}]
{1., 1.}
Why does the first try fail and the last try evaluate?
f
evaluates to a list of numbers, and NIntegrate is expecting just a number. $\endgroup$Indexed
like so{NIntegrate[Indexed[f[{x, y}], 1], {x, 0, 1}, {y, 0, 1}], NIntegrate[Indexed[f[{x, y}], 2], {x, 0, 1}, {y, 0, 1}]}
which gives{1., 1.}
$\endgroup$