Re: Problem when NIntegrate matrix
- To: mathgroup at smc.vnet.net
- Subject: [mg81356] Re: Problem when NIntegrate matrix
- From: Chris Chiasson <chris.chiasson at gmail.com>
- Date: Thu, 20 Sep 2007 03:52:15 -0400 (EDT)
- References: <fcqrrj$2jc$1@smc.vnet.net>
On Sep 19, 4:58 am, chiron1201 <hua... at cse.buaa.edu.cn> 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}] > > However, I can get the correct result by modifying the code manually. That is > > NIntegrate[{{1, 2, 3}, {2, 3, 4}, {3, 4, 5}}, {x, -1, 0}]+NIntegrate[{{2, 3,4}, {3, 4, 5}, {4, 5, 6}}, {x, 0, 1}] > > However, it is impossible for me to manually split the integration range to thousands of segments. Why this happens? What should I do if I want the first code be evaluated correctly? > > Thanks! the method below works in v6, but not in v5 due to some problem with NIntegrate In[1]:= Attributes@pwJoin = {Listable}; pwJoin[HoldPattern[Piecewise][condSet1_, def_], HoldPattern[Piecewise][condSet2_, def_]] := With[{jointConds = Join[condSet1, condSet2]}, Piecewise[jointConds, def]] pwCollapse@HoldPattern[Piecewise][arg : {{_?MatrixQ, _} ..}, def_] := pwJoin @@ MapThread[ Function[{mat, constr}, Map[Piecewise[{{#, constr}}, def] &, mat, {2}]], Transpose@arg] pwCollapse@ Piecewise[{{{{1, 2, 3}, {2, 3, 4}, {3, 4, 5}}, x < 0.00}, {{{2, 3, 4}, {3, 4, 5}, {4, 5, 6}}, x >= 0.00}}]; NIntegrate[%, {x, -1, 1}] Out[5]= {{3., 5., 7.}, {5., 7., 9.}, {7., 9., 11.}}