I'm not able to NIntegrate a function that has a numeric list as an argument. My original problem involves a compiled function, but a MWE is the following:
g[r : {__?NumericQ}, x_?NumericQ] := r;
NIntegrate[g[{2}, x], {x, 0, 10}]
This gives me the following error:
which I fail to understand, since
g[{2}, 0.0795732]
evaluates perfectly fine to {2}.
Other functions like Plot are fine, i.e. the following works as expected:
Plot[g[{2}, x], {x, 0, 10}]
Also, if we don't force the arguments to be numeric, i.e.:
gS[r_, x_] := r;
NIntegrate[gS[{2}, x], {x, 0, 10}]
everything works fine. But I do need to force them to be numeric because eventually I want to NIntegrate a compiled function. The example posted here is the simplest MWE I've been able to provide.
I would really appreciate any thoughts, since I'm quite lost here. Thank you so much, Luis
{2}
is not a number $\endgroup$NIntegrate[{2}, {x, 0, 1}]
evaluates just fine. The issue is that inNIntegrate[gS[{2}, x], {x, 0, 10}]
, the integrand won't evaluate to a number becausex
is not a number. On the face of it, I wouldn't know how to short-circuit the evaluation here, becauseEvaluate@gS[{2}, x]
of course yieldsgS[{2}, x]
, but it needs to be evaluated before theNIntegrate
so that {2} can integrate to {2.}. Luis, I suspect the thing that you are trying to do should be done in a different way. Perhaps the greater context would be helpful. $\endgroup$