Diving into symbolic computing with SymPy
In this recipe, we will give a brief introduction to symbolic computing with SymPy. We will see more advanced features of SymPy in the next recipes.
Getting ready
Anaconda should come with SymPy by default, but you can always install it with conda
install
sympy
.
How to do it...
SymPy can be used from a Python module, or interactively in Jupyter/IPython. In the Notebook, all mathematical expressions are displayed with LaTeX, thanks to the MathJax JavaScript library.
Here is an introduction to SymPy:
- First, we import SymPy and enable LaTeX printing in the Jupyter Notebook:
>>> from sympy import * init_printing()
- To deal with symbolic variables, we first need to declare them:
>>> var('x y')
- The
var()
function creates symbols and injects them into the namespace. This function should only be used in the interactive mode. In a Python module, it is better to use thesymbols()
function that returns the symbols:>>> x, y = symbols...