Book Image

Sage Beginner's Guide

By : Craig Finch
1 (1)
Book Image

Sage Beginner's Guide

1 (1)
By: Craig Finch

Overview of this book

Table of Contents (17 chapters)
Sage Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – computing sums of series


Enter the following code into an input cell in a worksheet, and evaluate the cell:

var('x, n, k')

f(x) = sin(x) / x^2
f.show()

print("Power series expansion around x=1:")
s(x) = f.series(x==1, 3)
s.show()

print("Sum of alternating harmonic series:")
h(k) = (-1)^(k + 1) * 1 / k
print h.sum(k, 1, infinity)

print("Sum of binomial series:")
h(k) = binomial(n, k)
print h.sum(k, 1, infinity)

print("Sum of harmonic series:")
h(k) = 1 / k
print h.sum(k, 1, infinity)    # Diverges

The results are shown in the following screenshot:

What just happened?

We started by defining a function and using the series method to compute a power series around the point x=1. The first argument to series is the point at which to create the series, and the second argument is the order of the computed series. Notice that Sages uses "big O" notation to denote the order of the series.

We then created several infinite series and computed their sums. Sage can compute the sum...