[Date Index]
[Thread Index]
[Author Index]
Re: Help please: Summing a list
*To*: mathgroup at smc.vnet.net
*Subject*: [mg13509] Re: [mg13480] Help please: Summing a list
*From*: Carl Woll <carlw at fermi.phys.washington.edu>
*Date*: Fri, 31 Jul 1998 04:33:24 -0400
*Sender*: owner-wri-mathgroup at wolfram.com
Hi Rob,
There are several problems with the statement
> PP[[i]]:=Sum[P[[n]],{n,0,i}];
The first problem is the use of double brackets instead of single
brackets. Using double brackets like you do above implies that PP is
already an object like a list with elements. This is what causes the
error message which Mathematica gives you.
The second problem is that in a function definition you should use an
argument with a pattern. That is, PP[i_] instead of PP[i]. Otherwise,
your definition only takes action when the argument is the letter i.
The final problem is that you probably don't want to have your sum go
from 0 to i, since the zeroth part of an expression is the head. For
example, if
s = {1,2,3}
then s[[0]] is List and not 1. So, putting the above together, you
probably want the definition
PP[i_] = Sum[ P[[n]], {n,1,i} ]
Carl Woll
Dept of Physics
U of Washington
On Sun, 26 Jul 1998 robpetersonSPAMME at iname.com wrote:
> I make a list of numbers, eg:
>
> P=Table[6,{x,0,110}]; (I have a more interesting list to use later if I
> get this working)
>
> Now I want to make another list PP in which each entry PP[[i]] is the
> sum of P's first i entries. I try
>
> PP[[i]]:=Sum[P[[n]],{n,0,i}];
>
> At the definition, I get the following error: Part::"pspec":
> "Part specification \!\(n\) is neither an integer nor a list of
> integers."
>
> I don't know how to make n an integer. In the definition of Sum[], it
> seems n is an integer unless you add a forth parameter "di" in the
> specification list such as
> Sum[f, {i, imin, imax, di}]
>
> Can anyone help me to generate this second list?
>
> Thanks, Rob
>
Prev by Date:
**Cluster-Analysis with Mathematica?**
Next by Date:
**problem with Needs[ ] command**
Previous by thread:
**Re: Help please: Summing a list**
Next by thread:
**Re: Help please: Summing a list**
| |