Adding piecewise functions with overlapping conditions

36 views
Skip to first unread message

Milind R

unread,
Oct 5, 2016, 11:35:57 AM10/5/16
to sympy

Hi,

I am trying to use the functionality of adding overlapping intervals from piecewise functions :

>>> p1 = Piecewise ( (1,(0 <= x) & (x < 1)) )
>>> p2 = Piecewise ( (1,(0.5 <= x) & (x < 1.5)) )
>>> p3 = p1 + p2
>>> p3



>>> p3._eval_interval(x,0,1.4)

What I expect is :

0    < x <= 0.5 --> 1
0.5 < x <= 1    --> 2
1    < x <   1.4 --> 1

What I get is :

0

Can sympy Piecewise do this? Is this the right tool for the job?

Reply all
Reply to author
Forward
0 new messages