For loops and sigma notation

I don't understand the sigma notation pretty well for some reason,

http://prntscr.com/f7v5lc

This would be
1
2
3
for(int i = 0; i <= 5; i++){
sum += ( 1 / pow(2,i) );
}


? Like it's that simple or does it have other meanings?
It's that simple.

The partial sum limits to 2 (it's a convergent geometric series with a = 1, r = 1 / 2), so instead of completing the loop you might as well just use the explicit formula for the mth partial sum
2 - (1 / (2 ^ m)) where m = 5.
Last edited on
It's also quite interesting in binary:
(1/2)^0 is 1
(1/2)^1 is 0.1 (in binary)
(1/2)^2 is 0.01 (in binary)
(1/2)^3 is 0.001 (in binary)
etc.

Your sum for i=0 to i=5 is just
1.11111 (in binary)
and all the other partial sums are similar.

For fractions other than the inverse powers of 2 you can, as @mbozzi points out, more quickly use the formula for the sum of a geometric series than doing the sum term by term.
Topic archived. No new replies allowed.