Python Math Functions with Programs

Spread the love

Python mathematical Functions:

We have good mathematical functions in python. we can save by using those. you have to import math library to access them. Here the best functions in math with program examples.

#Python math functions with programs import math a= [1,2,3,4,5,6] # sum of the valuves print('sum of values : ',sum(a)) # minimum value print('Minimum value of list : ',min(a)) # Maximum value print('Maximum value of list : ', max(a)) #print sqrt value print('Sqrt vale of 3 is : ',math.sqrt(a[3])) #print pi value print('pi value : ', math.pi) #ceil(x) Returns the smallest integer greater than or equal to x. print('ceil value of 105.22 : ', math.ceil(105.22)) #floor(x) Returns the largest integer less than or equal to x print('floor value of 105.22 : ',math.floor(105.22)) #fabs(x) Returns the absolute value of x print('fabs value of 105 : ',math.fabs(105)) #factorial(x) Returns the factorial of x print('factorial value of 4 : ',math.factorial(4)) #fmod(x, y) Returns the remainder when x is divided by y print('fmod value of 4, 9 : ',math.fmod(4,9)) #isnan(x) Returns True if x is a NaN print('is 5.5 Nan : ',math.isnan(5.5)) #exp(x) Returns e**x print('exp value of 2 : ',math.exp(2)) #expm1(x) Returns e**x - 1 print('expm1 value of 5 : ',math.expm1(5)) #pow(x, y) Returns x raised to the power y print('Power value of 2,2 : ',math.pow(2,2)) #log(x[, base]) Returns the logarithm of x to the base (defaults to e) print('log value of 4 : ',math.log(a[3])) #log1p(x) Returns the natural logarithm of 1+x print('log1p value of 4 : ',math.log1p(a[3])) #log2(x) Returns the base-2 logarithm of x print('log2 value of 4 : ',math.log2(a[3])) #log10(x) Returns the base-10 logarithm of x print('log10 value of 4 : ',math.log10(a[3])) #cos(x) Returns the cosine of x print('cos value of 3 : ',math.cos(a[3])) #hypot(x, y) Returns the Euclidean norm, sqrt(x*x + y*y) print('hypot value of 2,5 : ',math.hypot(2,5)) #sin(x) Returns the sine of x print('sin value of 2 :', math.sin(2)) #tan(x) Returns the tangent of x print('tan value of 20 : ',math.tan(20)) #degrees(x) Converts angle x from radians to degrees print('conver 20 radians to degrees : ', math.degrees(20)) #radians(x) Converts angle x from degrees to radians print('conver 1145.9155902616465 degrees to radians : ', math.radians(1145.9155902616465)) #cosh(x) Returns the hyperbolic cosine of x print('cosh value of 11 is ',math.cosh(11)) #sinh(x) Returns the hyperbolic cosine of x print('sinh value of 11 is',math.sinh(11)) #tanh(x) Returns the hyperbolic tangent of x print('tanh value of 11 is',math.tanh(11)) #erf(x) Returns the error function at x print('erf value of 11 is',math.erf(11)) #erfc(x) Returns the complementary error function at x print('erfc value of 11 is ',math.erfc(11)) #gamma(x) Returns the Gamma function at x print('gamma value of 10 is ' ,math.gamma(10)) #lgamma(x) Returns the natural logarithm of the absolute value of the Gamma function at x print('lgamma value of 10 is' ,math.lgamma(10))

Output:

sum of values : 21
Minimum value of list : 1
Maximum value of list : 6
Sqrt vale of 3 is : 2.0
pi value : 3.141592653589793
ceil value of 105.22 : 106
floor value of 105.22 : 105
fabs value of 105 : 105.0
factorial value of 4 : 24
fmod value of 4, 9 : 4.0
is 5.5 Nan : False
exp value of 2 : 7.38905609893065
expm1 value of 5 : 147.4131591025766
Power value of 2,2 : 4.0
log value of 4 : 1.3862943611198906
log1p value of 4 : 1.6094379124341003
log2 value of 4 : 2.0
log10 value of 4 : 0.6020599913279624
cos value of 3 : -0.6536436208636119
hypot value of 2,5 : 5.385164807134504
sin value of 2 : 0.9092974268256817
tan value of 20 : 2.237160944224742
conver 20 radians to degrees : 1145.9155902616465
conver 1145.9155902616465 degrees to radians : 20.0
cosh value of 11 is 29937.07086594976
sinh value of 11 is 29937.07084924806
tanh value of 11 is 0.9999999994421064
erf value of 11 is 1.0
erfc value of 11 is 1.4408661379436957e-54
gamma value of 10 is 362880.0l
gamma value of 10 is 12.801827480081467

Ref:

https://docs.python.org/3/library/math.html

admin

admin

Leave a Reply

Your email address will not be published. Required fields are marked *