It is formula that I use to find distance traveled by bouncing ball:
 
where: 
h(n) - total distance traveled by bouncing ball
H - a ball drop height 
n - number of bounces
e - coefficient of restitution 
I created Matlab function to do that calculation:
function distance = totalDistance(H, n, e)
sum = 0;
bounceHeight = 0;
    for i = 1:n
        bounceHeight  = H*(e^(2*n));
        sum = sum + e^(2*n);
    end
distance = H+(2*H*sum);
end
This function takes initial drop height H, number of bounces n, coefficient of restitution e and returns me total distance traveled by bouncing ball. 
Then I call this function in command window to check:
totalDistance(2,2,2)
The function returns wrong result. It returns 130 instead of 82.
Why the program does not work properly?
 
    