Sharedpower.sagewsOpen in CoCalc
# Turn on typeset mode
%typeset_mode True
# Define a power series
a(n) = x^n/2^n
# Define partial sums - note the 0!!!
def s(k):
    return sum([a(i) for i in [0..k]])
s(5)
132x5+116x4+18x3+14x2+12x+1\displaystyle \frac{1}{32} \, x^{5} + \frac{1}{16} \, x^{4} + \frac{1}{8} \, x^{3} + \frac{1}{4} \, x^{2} + \frac{1}{2} \, x + 1
# Plot s(5) from -5 to 5
plot(s(5), (-5,5))
# Plot a bunch of partial sums
plot(s(0))+plot(s(1))+plot(s(2))
# Quicker method
sum([plot(s(i),(-5,5)) for i in range(0,5)])