Summation to infinity?

Summation to infinity?

Post by Andreas Sc » Thu, 09 Oct 2003 00:37:59


I tried to see the plot for such an equation (summation):

sum n from 1 to infinity: (13/18) ** (n - 1)

I did it with a recursive function:

sum(n)=0.7222222 ** (n-1) + (n>1 ? sum(n-1) : 0)

But why is there such a great difference between these two plots:

gnuplot> set yrange [0:5]
gnuplot> plot [-10:90] sum(x)
gnuplot> plot [-10:91] sum(x)

The first is very smooth, while the second is very bumpy for the very same
values of x.

And, is there an easier or better way for plotting a summation than
defining a recursive function?
It is limited to like x=100 maximally, after that I get a stack overflow!

Thanks for your hints!

Summation to infinity?

Post by Hans-Bernh » Thu, 09 Oct 2003 01:15:11

Because x is a floating-point number, whereas your function expects
only integer arguments, but doesn't enforce that fact.

Alternatively it would also would help if you modified 'set samples'
along with the xrange such that all sampling points are integers. Try

set samples 101
plot [-10:91] sum(x)

some time.

In the case at hand: yes, because there's a closed-form solution for
the finite geometrical series. Find it in your Mittelstufe maths
textbook (ca. Klasse 8 oder 9) ;-)

But not generally. gnuplot is not a heavy-duty mathematical analysis
tool. If you want that, get MuPAD, Octave or SciLab instead.

Hans-Bernhard Broeker ( XXXX@XXXXX.COM )
Even if all the snow were burnt, ashes would remain.


Summation to infinity?

Post by Peter Weil » Thu, 09 Oct 2003 01:18:52

There seems to be a problem with the sampling. If you use "set samples"
to set the sampling rate to >>100 (100 is the default), e.g. 10000 which
could take a while to plot, the two graphs are very similar and not
smooth at all!

No idea for the rest of your questions...
Gruesse von