Defining Piecewise function in python getting TypeError: cannot determine truth value of Relational

I am trying to define a piecewise function in python to be able to then evaluate at different points and also transform the function i.e. f(x) orf(0) or f(x-h) I have done the following but getting the following error: raise TypeError("cannot determine truth value of Relational")

TypeError: cannot determine truth value of Relational Is anyone able to see why please?

from numpy import piecewise 
from scipy import *
from import x
from sympy.utilities.lambdify import lambdify, implemented_function
from sympy import Function
from sympy import *
h = 0.5 
a = -1
b = 2
x = Symbol('x')
expr = piecewise((0, x-a <=  -2*h), ((1/6)*(2*h+(x-a))**3, -2*h<=x-a<=-h), (2*h**3/3-0.5*(x-a)**2*(2*h+(x-a)), -h<= x-a<= 0), (2*(h**3/3)-0.5*(x-a)**2*(2*h+(x-a)), 0<=x-a<=2*h), ((1/6)*(2*h-(x-a))**3, h<=x-a<=2*h), (0, x-a<=2*h))
p = lambdify((x, a,b,h), expr)

Read more here:

Content Attribution

This content was originally published by peaapod at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: