Thursday, October 9, 2025
HomeLanguagessympy.stats.Triangular() in Python

sympy.stats.Triangular() in Python

With the help of sympy.stats.Triangular() method, we can get the continuous random variable which represents the triangular distribution.

Syntax : sympy.stats.Triangular(name, a, b, c)
Where, a, b and c are real number.

Return : Return the continuous random variable.

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




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


Output :

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

Example #2 :




# Import sympy and Triangular
from sympy.stats import Triangular, density
from sympy import Symbol, pprint
  
z = 5
a = 1.2
b = 1.3
c = 1.27
  
# Using sympy.stats.Triangular() method
X = Triangular("x", a, b, c)
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
32342 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6713 POSTS0 COMMENTS
Nicole Veronica
11876 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11937 POSTS0 COMMENTS
Shaida Kate Naidoo
6833 POSTS0 COMMENTS
Ted Musemwa
7092 POSTS0 COMMENTS
Thapelo Manthata
6786 POSTS0 COMMENTS
Umr Jansen
6789 POSTS0 COMMENTS