IPython Notebook Sympy Math Rendering

感情迁移 提交于 2019-12-03 09:00:36

问题


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?


回答1:


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




回答2:


I recently had the same problem, and I'm using Linux Crunchbang, which is a derivative of Redhat I think. Originally I installed sympy using

pip install sympy

However, this led to the above problem as described. So then I went to the sympy webpage and cloned the git repository to a folder. Then it can be installed (once in the local folder) by using

python setup.py install

After that everything worked fine, so I think it had something to do with the version used. For the record, the commands I used to initialize the printing in python were

import sympy
sympy.init_printing()



回答3:


Import:

from sympy import *
init_printing()

Example:

x = symbols('x')
a = Integral(cos(x)*exp(x), x)
Eq(a, a.doit())

Output:



来源:https://stackoverflow.com/questions/16152040/ipython-notebook-sympy-math-rendering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!