MathGroup Archive 2009

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

Search the Archive

Re: error with Sum and Infinity

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102265] Re: error with Sum and Infinity
  • From: pfalloon <pfalloon at gmail.com>
  • Date: Mon, 3 Aug 2009 05:47:09 -0400 (EDT)
  • References: <h53o1e$1i8$1@smc.vnet.net>

On Aug 2, 7:59 pm, Llewlyn <tommaso.biancal... at gmail.com> wrote:
> Hi experts,
>
> i'm very new to Mathematica and this is my first problem. I define a
> function that is 0 everywhere:
> t[i_] := 0
> expect for point i =3 that is:
>  t[3] = 1
> If now i evaluate the finite sum i obtain 1 as expected
> Sum[ t[i], {i, 1, 10}]
> Out = 1
> but if i try do the same with infinity i obtain
> In[808]:= Sum[ t[i], {i, 1, Infinity}]
> Out[808]= 0
> instead of 1 expected. Any advice?
>
> tb

It doesn't work with Infinity as the upper limit because in that case
the function works by first symbolically evaluating the argument. In
this case, for symbolic i, t[i] happily returns 0.

Using a more strict definitions will resolve the issue. One solution
is to modify the first definition to only match integer arguments:

In[202]:= Clear[t];
t[i_Integer] := 0
t[3] = 1;
Sum[t[i], {i,1,Infinity}]
Out[205]= \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 1\), \(\[Infinity]\)]\(t[i]\)\)
In[206]:= N[%]
Out[206]= 1.

Note that here you need to use N to get a numeric result; this is non-
ideal, but at least it is no longer returning a spurious result.

A better solution is a piecewise definition (in the Piecewise function
the default value is 0, so you only need to specify the value at i=3):

In[215]:= Clear[t];
t[i_] = Piecewise[{{1, i == 3}}];
Sum[t[i], {i,1,Infinity}]
Out[217]= 1

But for the specific case you give, the neatest solution would be to
define t as a Kronecker delta function:

In[221]:= t[i_] := KroneckerDelta[i-3]
Sum[t[i], {i,1,Infinity}]
Out[222]= 1

There are many ways to solve this, but I guess the moral is to be
careful when using multiple definitions relying on pattern matching of
the argument -- since it can often have this kind of unexpected
effect.

Cheers,
Peter.


  • Prev by Date: Re: error with Sum and Infinity
  • Next by Date: Re: Re: Eigenvalues of sparse arrays
  • Previous by thread: Re: error with Sum and Infinity
  • Next by thread: Re: error with Sum and Infinity