Re: Strange behavior of NSum on 4.0
- To: mathgroup at smc.vnet.net
- Subject: [mg28101] Re: [mg28045] Strange behavior of NSum on 4.0
- From: Tomas Garza <tgarza01 at prodigy.net.mx>
- Date: Fri, 30 Mar 2001 04:12:59 -0500 (EST)
- References: <200103290824.DAA03023@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
The problem is not environmental. Actually, there is an incorrect usage of the iterator in NSum. If you refer to the on-line Help Browser under NSum, you'll see that the correct usage is NSum[f, {i, imin, imax}] or NSum[f, {i, imin, imax,di}] . You can't omit the "imin" part, as you may in the definition of Sum. This is because NSum uses either the Euler-Maclaurin (Integrate) or Wynn epsilon (Fit) method, which both require imin and imax to be supplied. The problem won't appear in the case of Sum with imin omitted. BTW, why do you want to use NSum instead of plain Sum? The former gives a numerical approximation to the sum. Tomas Garza Mexico City ----- Original Message ----- From: "Ken Kikuchi" <kikuchi at neti.com> To: mathgroup at smc.vnet.net Subject: [mg28101] [mg28045] Strange behavior of NSum on 4.0 > 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 > >
- References:
- Strange behavior of NSum on 4.0
- From: Ken Kikuchi <kikuchi@neti.com>
- Strange behavior of NSum on 4.0