I am trying to use sympy in a Jupyter notebook to document and perform a series of mathematical cacluations in a reporducible way.
If I define the following:
from sympy import *
init_printing()
x, y, z = symbols("x y z")
x=y+z
x
then I can display the value of x
(that is, y+z
).
How do I display the full equation (x=y+z
)?
Running Eq(x,y+z)
, even with evaluate=False
) returns the expression with the value of x
substituted (y+z=y+z
).
I tried using Eq(S('x'),y+z)
, also Eq(S('x'),x)
and sympy
keep returning a boolean variable.
So I found a way to display it using the Ipython
built-in functions:
from sympy import *
from IPython.display import display, Math
init_printing()
x, y, z = symbols("x y z")
x=y+z
display(Math('x = '+latex(x)))
I think that this is a more general solution to the problem.
Although you first declare x
as a sympy.Symbol
, once you perform the assignment x=y+z
, x
becomes an alias for y+z
. Whenever you use x
from that point after, x
will be automatically translated by python as y+z
.
If you insist on this workflow, you could use Eq(S('x'),y+z)
to display the equation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With