Book Image

IPython Interactive Computing and Visualization Cookbook

By : Cyrille Rossant
Book Image

IPython Interactive Computing and Visualization Cookbook

By: Cyrille Rossant

Overview of this book

Table of Contents (22 chapters)
IPython Interactive Computing and Visualization Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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

SymPy is a pure Python package with no other dependencies, and as such, it is very easy to install. With Anaconda, you can type conda install sympy in a terminal. On Windows, you can use Chris Gohlke's package (www.lfd.uci.edu/~gohlke/pythonlibs/#sympy). Finally, you can use the pip install sympy command.

How to do it...

SymPy can be used from a Python module, or interactively in IPython. In the notebook, all mathematical expressions are displayed with LaTeX, thanks to the MathJax JavaScript library.

Here is an introduction to SymPy:

  1. First, we import SymPy and enable LaTeX printing in the IPython notebook:

    In [1]: from sympy import *
            init_printing()
  2. To deal with symbolic variables, we first need to declare them:

    In [2]: var('x y')
    Out[2]: (x, y)
  3. The var() function creates symbols and injects...