1 year ago

#351874

test-img

Eileen

Integrate piecewise function. (TypeError: cannot determine truth value of Relational)

My codes is as follows, which aims to calculate the integral of a piecewise function. But it reports the error: TypeError: cannot determine truth value of Relational

import numpy as np
import math
import sympy 
def phi(x,i):
    if i==0:
        return Piecewise((-1/10,0<x<1),(0,True))
    elif i==1:
        return Piecewise((1/10,0<x<1),(-1/10,1<x<3),(0,True))
    else:
        return None
from sympy import *
x=symbols('x')
M[1,1]=integrate(phi(x,1),(x,0,6))

<ipython-input-10-c387d7b33e95> in phi(x, i)
      3         return Piecewise((-1/10,0<x<1),(0,True))
      4     elif i==1:
----> 5         return Piecewise((1/10,0<x<1),(-1/10,1<x<3),(0,True))
      6     else:
      7         return None

/opt/anaconda3/lib/python3.8/site-packages/sympy/core/relational.py in __bool__(self)
    396 
    397     def __bool__(self):
--> 398         raise TypeError("cannot determine truth value of Relational")
    399 
    400     def _eval_as_set(self):

TypeError: cannot determine truth value of Relational

python

piecewise

0 Answers

Your Answer

Accepted video resources