MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: "Help please: Summing a list"


Hello Rob,

in place of
PP[[i]]:=Sum[P[[n]],{n,0,i}];

use the following definition:

PP[i_]:=Sum[P[[n]],{n,1,i}]; (*1*)

or, if you really want to use the function PP with only integer
arguments, you can use
PP[i_Integer]:=Sum[P[[n]],{n,1,i}]; (*2) but in your case this is not a
problem to use (*1*). Take a look about definition of a function to
understand the use of i_ in place of i in the definition.
A Mathematica list begins always with the indice 1, if you ask P[[0]]
you will have the Head of P, i.e.

In[3]:=P[[0]]
gives
Out[3]:=List
Have a look at FullForm[P] to see why.

A bientôt,
Robert Erra.


  • Prev by Date: Overriding default rules
  • Next by Date: Mathematica and Win98?
  • Previous by thread: Overriding default rules
  • Next by thread: Mathematica and Win98?