Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPython Notebook Sympy Math Rendering

I have just started with using IPython Notebook and have been fascinated by its power. I have been using a few examples available on the net to get started with. I was following this tutorial: http://nbviewer.ipython.org/url/finiterank.com/cuadernos/suavesylocas.ipynb but the maths output is not getting rendered as expected. Below is the my code and the output:

In [30]:

%load_ext sympyprinting
%pylab inline

from __future__ import division
import sympy as sym
from sympy import *

init_printing()

x,y,z=symbols("x y z")
k,m,n=symbols("k m n", integer=True)

The sympyprinting extension is already loaded. To reload it, use:
  %reload_ext sympyprinting

Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.kernel.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.

In [31]:

t = sin(2*pi*x*(k**2))/ (4*(pi**2)*(k**5)) + (x**2) / (2*k)
t
Out[31]:
  2      ⎛     2  ⎞
 x    sin⎝2⋅π⋅k ⋅x⎠
─── + ─────────────
2⋅k         2  5   
         4⋅π ⋅k   

I have tried other examples also, and they are also not getting rendered properly. Where am I going wrong?

like image 351
DotPi Avatar asked Apr 22 '13 16:04

DotPi


People also ask

Does Jupyter notebook have SymPy?

SymPy can be used from a Python module, or interactively in Jupyter/IPython.

Is IPython deprecated?

The IPython console is now deprecated and if you want to start it, you'll need to use the Jupyter Console, which is a terminal-based console frontend for Jupyter kernels.

What does SymPy Init_printing do?

With the help of sympy. init_printing() method, we are able to print the unicode characters for mathematical expressions.

Is IPython and Python same?

IPython is an interactive command-line terminal for Python. It was created by Fernando Perez in 2001. IPython offers an enhanced read-eval-print loop (REPL) environment particularly well adapted to scientific computing. In other words, IPython is a powerful interface to the Python language.


1 Answers

I had the same problem. Try

from sympy.interactive import printing
printing.init_printing(use_latex=True)

instead of

%load_ext sympyprinting

I am using sympy 0.7.2

like image 93
Antony Avatar answered Sep 19 '22 17:09

Antony