Issue
from IPython.display import display as mathPrint
from sympy import *
x = symbols("x")
mathPrint(Eq(abs(x), Piecewise((-x, x < 0), (0, x == 0), (x, x > 0)), evaluate=False))
It's printing the expression like this:
It isn't showing the 2nd condition of the function which should be 0 for x = 0.
How can I get the desired output? Should I need to use any other display function?
Solution
There are two problems. The first is that you are passing evaluate=False
to Eq
rather than to Piecewise
(check the brackets carefully). The second problem is that you are passing th condition x == 0
which simply evaluates to False
. To make a symbolic representation of an equality you should use Eq
. In that case evaluate=False
is not even needed (in this example):
In [145]: Piecewise((-x, x < 0), (0, Eq(x, 0)), (x, x > 0))
Out[145]:
⎧-x for x < 0
⎪
⎨0 for x = 0
⎪
⎩x for x > 0
Answered By - Oscar Benjamin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.