2

enter image description here

I wonder if there is a way to specify that p is greater than 0 and smaller than pi, so that I don't get "cannot determine truth value of Relational".

CDJB
  • 14,043
  • 5
  • 29
  • 55
ramhuw
  • 61
  • 3

1 Answers1

2

You can do something like the following, using two booleans rather than the relational 0 <= x <= p.

import sympy as sp

x, h, p = sp.symbols('x h p')

fx = sp.Piecewise(
                ((x*h)/p, ((0 <= x) & (x <= p))),
                ((h*(sp.pi - x))/(sp.pi - p), ((p <= x) & (x <= sp.pi)))
            )

Which gives

fx

CDJB
  • 14,043
  • 5
  • 29
  • 55