---
author: Nathan Carter (ncarter@bentley.edu)
---

This answer assumes you have imported SymPy as follows.


```python
from sympy import *                   # load all math functions
init_printing( use_latex='mathjax' )  # use pretty math output
```

We define here the same sequence we defined in the task entitled
how to define a mathematical sequence.


```python
var( 'n' )                       # use n as a symbol
a_n = 1 / ( n + 1 )              # formula for a term
seq = sequence( a_n, (n,0,oo) )  # build the sequence
seq
```




$\displaystyle \left[1, \frac{1}{2}, \frac{1}{3}, \frac{1}{4}, \ldots\right]$



We can turn it into a mathematical series by simply replacing the word
`sequence` with the word `Sum`.  This does not compute the answer, but
just writes the series for us to view.  In this case, it is an infinite
series.


```python
Sum( a_n, (n,0,oo) )
```




$\displaystyle \sum_{n=0}^{\infty} \frac{1}{n + 1}$



You can compute the answer by appending the code `.doit()` to the above code,
which asks SymPy to "do" (or evaluate) the sum.


```python
Sum( a_n, (n,0,oo) ).doit()
```




$\displaystyle \infty$



In this case, the series diverges.

We can also create and evaluate finite series by replacing the `oo` with a number.


```python
Sum( a_n, (n,0,10) ).doit()
```




$\displaystyle \frac{83711}{27720}$



3fef85e094faf3a72dd070cfb79e1a5a9075cd2e
ipynb
Jupyter Notebook
database/tasks/How to define a mathematical series/Python, using SymPy.ipynb
nathancarter/how2data
7d4f2838661f7ce98deb1b8081470cec5671b03a
MIT
database/tasks/How to define a mathematical series/Python, using SymPy.ipynb
nathancarter/how2data
7d4f2838661f7ce98deb1b8081470cec5671b03a
MIT
database/tasks/How to define a mathematical series/Python, using SymPy.ipynb
nathancarter/how2data
7d4f2838661f7ce98deb1b8081470cec5671b03a
MIT
2021-07-18T19:01:29.000Z
2022-03-29T06:47:11.000Z
Qwen/Qwen-72B
1. YES
2. YES