Re: Strange behavior of NSum on 4.0
- To: mathgroup at smc.vnet.net
- Subject: [mg28100] Re: Strange behavior of NSum on 4.0
- From: "Albert REINER" <Use-Author-Address-Header at [127.1]>
- Date: Fri, 30 Mar 2001 04:12:57 -0500 (EST)
- Author-address: areiner <AT> tph <DOT> tuwien <DOT> ac <DOT> at
- Organization: mail2news@nym.alias.net
- References: <99uruh$5vv@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On Thu, Mar 29, 2001 at 03:32:17AM -0500, Ken Kikuchi wrote: > 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}." > The error message is complaining about a part specification, isn't it? So let's have a look at what NSolve hands to the "Integrand" as i: ,---- | NSum[Print[i];a[[i]],{i,25}] | i | | i | | i | | 25. | | 25. | | 24. | | 23. | | 15. | | 15 | | 14. | | 14 | | 13 | | 12 | | 11 | | 10 | | 9 | | 8 | | 7 | | 6 | | 5 | | 4 | | 3 | | 2 | | 1 | | 20.5 | | 41 | -- | 2 `---- Apparently, using NSolve Mathematica makes i non-integer (like 25. or 20.5), which is then re-tried as exact number (25, or 41/2). So most of the time this will do what you expect, but a[[41/2]] is bound to give you an error. Now, don't ask me why NSum wants to have a look at 41/2. At the same time I do not understand what NSum is good for in this example anyway. Albert.