Re: NIntegrate with Numeric Matrix Function
- To: mathgroup at smc.vnet.net
- Subject: [mg105815] Re: NIntegrate with Numeric Matrix Function
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Sun, 20 Dec 2009 06:54:25 -0500 (EST)
On 12/19/09 at 6:25 AM, akovalev at physics.ucla.edu wrote: >I have a function defined via SetDelayed (:=) with _?NumberQ in the >argument to speed up integration. It works fine when the result of >the function is a scalar. However, when the result of the function >is a vector I get an error "Integrand is not numerical". I know that >removing _?NumberQ solves the problem but then integration becomes 3 >times slower. >Is there a way to let NIntegrate know that it should expect a vector >as an input? You are having a problem since In[1]:= NumberQ[RandomReal[1, {5}]] Out[1]= False That is _?NumberQ will never match a list and your function will return its arguments unevaluated causing the error message. The pattern __?NumberQ will match a sequence of numbers rather than a single number. So, perhaps something like In[2]:= f[x__?NumberQ] := Total[{x}] In[3]:= f @@ RandomReal[1, {5}] Out[3]= 3.08095 will do what you need. Note, the pattern __?NumberQ also doesn't match a list. I get around this problem using the syntax f@@ instead of f@ and reconstituting the list in the definition of f.