Re: Strange behavior of NSum on 4.0
- To: mathgroup at smc.vnet.net
- Subject: [mg28070] Re: Strange behavior of NSum on 4.0
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Fri, 30 Mar 2001 04:12:22 -0500 (EST)
- References: <99uruh$5vv@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Ken, I don't know the algorithms that are being used but from the error messages it looks as if NSum is expecting an everywhere defined function -- so let's give it one: if = Interpolation[a] InterpolatingFunction[{{1,25}},<>] NSum[if[i],{i,25}] 325. On this basis it looks as if using the option Method->Fit might work, but NSum[a[[i]],{i,25}, Method ->Fit] Part::partw: Part 26 of \[LeftSkeleton]1\[RightSkeleton] does not exist. ............... NSum[a[[i]], {i, 25}, Method -> Fit] However, NSum[a[[i]],{i,24}, Method ->Fit] 300. Which is consistent with what you found. So again it looks as if extra information is asked for. Of course the simplest way to sum this list is Plus@@a 325 -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 "Ken Kikuchi" <kikuchi at neti.com> wrote in message news:99uruh$5vv at smc.vnet.net... > I encountered a strange behavior with NSum on Mathematica 4.0 on Mac. > The following is a simplified example about sum of 1 to 25. > > In[1]:= a = Range[25] > Out[1]= > {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, > 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25} > > In[2]:= NSum[a[[i]], {i, 25}] > > I expected the result as 325 but received the following strange error > messages. > > Part::pspec : > Part specification 41/2 is neither an integer nor a list of > integers. > ... > NIntegrate::inum : > Integrand <<1>>[[41/2]] is not numerical at {1}={41/2}." > > However, the same code works fine up to 24. > In[23]:= NSum[a[[i]], {i, 24}] > Out[23]= 300. > > It works fine if not using Part. > In[3]:= NSum[i, {i, 25}] > Out[3]= 325. > > But Part works fine with N while manual noted -- N[Sum[...]] calls NSum. > In[4]:= N[Sum[a[[i]], {i, 25}]] > Out[4]= 325. > > And Sum works too. > In[5]:= Sum[a[[i]], {i, 25}] > Out[5]= 325 > > My version is, > In[6]:= $Version > Out[6]= "4.0 for Power Macintosh (July 26, 1999)" > > I am not sure it's only my environmental problem or my incorrect usage. > Could anyone help me? > > Many thanks, > Ken > >