function s_sum=sgs(q,n) %Calculates the sum of n terms of a %geometric series with progression q s=[]; s(1)=1; for i=1:n; s(i+1)=s(i)+q^i; end; s_sum=s(end)