You can use Sage to easily find the partial sums of an infinite series. Here is an example that adds the first 100 terms of the Harmonic series: \(1+ \frac{1}{2} + \frac{1}{3} + \ldots + \frac{1}{100}\).

Here is a quick explanation of the code above.

Step 1

Make a list of the terms in the series:

[1/n for n in range(1,101)]

Notice that the command range(1,101) tells Sage to use the numbers from 1 up to 101, but not including 101! Sage is based on the Python programming language, and that is just how the range function works in Python.

Step 2

Use the sum() function to add up the terms in the series:

sum([1/n for n in range(1,101)])

This works, but Sage gives us the exact answer which is a fraction. That isn't really what we want, so we need one more step.

Step 3

Convert the fraction to a decimal using the function N():

N(sum([1/n for n in range(1,101)]))

That's it! Feel free to adjust the code above on any homework problems that asks you to compute a partial sum.