Re: Problem when NIntegrate matrix
- To: mathgroup at smc.vnet.net
- Subject: [mg81360] Re: Problem when NIntegrate matrix
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Thu, 20 Sep 2007 03:54:28 -0400 (EDT)
- References: <fcqrrj$2jc$1@smc.vnet.net>
chiron1201 wrote: > Hi all! > > I can not understand why there is a NIntegrate::inum error when I try to evaluate the following code > > TEST = Piecewise[{ > {{{1, 2, 3}, {2, 3, 4}, {3, 4, 5}}, #1 < 0.00}, > {{{2, 3, 4}, {3, 4, 5}, {4, 5, 6}}, #1 >= 0.00}, > }] &; > > NIntegrate[TEST[x], {x, -1, +1}] My guess is that NIntegrate[] evaluates its argument without x having a numerical value (perhaps it tries to Compile[] it?), and makes assumptions about the dimensions of the integrand based on this result. Piecewise[...] is not a matrix (List of Lists), but a single expression. But with a numerical argument is evaluates to a matrix. This might confuse NIntegrate[]. In[1]:= f[x_?NumericQ] := {1, 2} g[x_] := {1, 2} h[x_] := {x, 2 x} In[4]:= NIntegrate[f[x], {x, 0, 3}] During evaluation of In[4]:= NIntegrate::inum: Integrand f[x] is not \ numerical at {x} = {0.023872}. >> During evaluation of In[4]:= NIntegrate::inum: Integrand f[x] is not \ numerical at {x} = {0.023872}. >> Out[4]= NIntegrate[f[x], {x, 0, 3}] In[5]:= NIntegrate[g[x], {x, 0, 3}] Out[5]= {3., 6.} In[6]:= NIntegrate[h[x], {x, 0, 3}] Out[6]= {4.5, 9.} Of course, this explanation does not solve your problem ... (and it might even be flawed) ... -- Szabolcs