Saturday, October 18, 2025
HomeLanguagessympy.stats.Trapezoidal() in Python

sympy.stats.Trapezoidal() in Python

With the help of sympy.stats.Trapezoidal() method, we can get the continuous random variable which represents the Trapezoidal distribution by using this method.

Syntax : sympy.stats.Trapezoidal(name, a, b, c, d)
Where, a, b, c and d are real number.
Return : Return the continuous random variable.

Example #1 :
In this example we can see that by using sympy.stats.Trapezoidal() method, we are able to get the continuous random variable representing Trapezoidal distribution by using this method.




# Import sympy and Trapezoidal
from sympy.stats import Trapezoidal, density
from sympy import Symbol, pprint
  
z = Symbol("z")
a = Symbol("a", positive = True)
b = Symbol("b", positive = True)
c = Symbol("c", positive = True)
d = Symbol("d", positive = True)
  
# Using sympy.stats.Trapezoidal() method
X = Trapezoidal("x", a, b, c, d)
gfg = density(X)(z)
  
pprint(gfg)


Output :

/ -2*a + 2*z
|————————- for And(a z)
|(-a + b)*(-a – b + c + d)
|
| 2
| ————– for And(b z)
= z, c <= z)
|(-c + d)*(-a – b + c + d)
|
\ 0 otherwise

Example #2 :




# Import sympy and Trapezoidal
from sympy.stats import Trapezoidal, density
from sympy import Symbol, pprint
  
z = 0.43
a = 2
b = 4
c = 5
d = 8
  
# Using sympy.stats.Trapezoidal() method
X = Trapezoidal("x", a, b, c, d)
gfg = density(X)(z)
  
pprint(gfg)


Output :

0

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS