Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

Python language mathematical function

Posted on April 15, 2017September 15, 2019

Table of Contents

  • Python language mathematical function
    • Python language mathematical function
      • Power and logarithm function
      • Angular conversion function
      • Trigonomatric function
      • Hyperbolic functions              

Python language mathematical function

In this tutorial, we will discuss the Python language mathematical function. Python provides built-in function for mathamatical calculaitions.

Python language mathematical function

Number-theoretic and representation function  

1. abs – this is a built -in function in python. We execute it with single argument. abs function returns the absolute value of that argument.

Output
10.7
10.7
35.1

 

2. fabs – fabs function is used to compute absolute value of any floating point number. If a number contains any negative (-) sign , it removes and returns as a positive number.

Output
10.743
10.745
35.143

3. ceil: This function rounds up to the next highest value of the given value.
Example
Output – 11.0
4. floor: This function rounds down to the next lowest value of the given value.
Example
Output – 10.0
5. factorial function – This function returns the factorial of the positive integer number.
Output
120
24
6
6. fmod function – Function fmod(x,y) returns x%y . But the difference of x%y is preferred when working with integers fmod(x,y) and is used when working with floats.
Output
1.0
2.0
-1.0
-1.3
7. sum function – This function helps to sum up list of values
Output
19.87654
7.87654
 
8. fsum
 
9. round function – return the floating point value number rounded  to n digits. round is a built-in function.
 
Syntex
 
round(number,[ndigits])
Example
 
Output
(’round this 34.34567,2′, 34.35)
(’round this 34.34567,3′, 34.346)
(’round this 34.34567,4′, 34.3457)
(’round this 34.34567,5′, 34.34567)
10. trunc function – this function returns the truncated integer of x. it  defines math module in python.
Syntex
 
trunc(x)
Example
Output
(‘trunc value of 3.4567:’, 3)
(‘trunc value of 3.4567:’, -3)
(‘trunc value of 3.4567:’, 6)
 

Power and logarithm function

 
1. exp() function
Python exp() function returns the exponential value of x with natural base e. It’s equal to math.e** operator/ It is a method of math module.
Syntex
exp(x)
Example
Output
(‘the value of math.e:’, 2.718281828459045)
(‘exp(1) value is:’, 2.718281828459045)
(‘exp(1) value is:’, 7.38905609893065)
(‘exp(1) value is:’, 20.085536923187668)
(‘exp(1) value is:’, 54.598150033144236)
2. log(x) function
Python log|(x,base) function returns the logarithm of x to the given base. If the base is not specified , it returns the natural logarithm of x.
Syntex
log|(x,base)
Example
 
Output
math.log(100.00): 4.60517018599
math.log(10.00): 2.30258509299
math.log(1.00): 0.0
math.log(math.e): 1.0
3. log10(x) function
Python log10|(x) function returns the base – 10 logarithm of x
Syntex
log|10(x)
Example
Out put
math.log10(2): 0.301029995664
math.log10(5): 2.30258509299
math.log10(1.00): 0.0
math.log10(math.e): 1.0
4. pow() function
Returns the x raised to the power y(X**y)
Syntex
pow(x,y)
Example
Output
The pow()value of(2,3) : 8.0
The pow()value of(3,4) : 81.0
The pow()value of(10,2) : 100.0
The pow()value of(10,10) : 10000000000.0
5. sqrt() function
 Returns the x raised to the power y(X**y)
Syntex
sqrt(x)
Example

Angular conversion function

1. degrees() function
 Returns the angle x as degrees
Syntex
degrees(x)
Example
Output
The degree of 2 : 114.591559026
The degree of 3 : 171.887338539
The degree of -3 : -171.887338539
The degree of 0 : 0.0
The degree of pi : 180.0
The degree of pi/2 : 90.0
The degree of pi/4 : 45.0
2. radians() function
 Returns angle x as radians
Syntex
radians(x)
Example
Output
The radians of 2 : 0.0349065850399
The radians of 3 : 0.0523598775598
The radians of -3 : -0.0523598775598
The radians of 0 : 0.0
The radians of pi : 0.0548311355616
The radians of pi/2 : 0.0274155677808
The radians of pi/4 : 0.0137077838904

Trigonomatric function

1. sin() function
 Returns the sine of the  x radians
Syntex
sin(x)
Example
Output
The sin of 2 : 0.909297426826
The sin of 3 : 0.14112000806
The sin of -3 : -0.14112000806
The sin of 0 : 0.0
The sin of pi : 1.22464679915e-16
The sin of pi/2 : 1.0
The sin of pi/4 : 0.707106781187
2. cos() function
 Returns the cosine of the  x radians
Syntex
cos(x)
Example
Output
The cosine of 2 : -0.416146836547
The cosine of 3 : -0.9899924966
The cosine of -3 : -0.9899924966
The cosine of 0 : 1.0
The cosine of pi : -1.0
The cosine of pi/2 : 1.0
3. tan() function
 Returns the tangent of the  x radians
Syntex
tan(x)
Example
Output
The tangent of 2 : -2.18503986326
The tangent of 3 : -0.142546543074
The tangent of -3 : 0.142546543074
The tangent of 0 : 0.0
The tangent of pi : -1.22464679915e-16
The tangent of pi/2 : 1.63312393532e+16
4. asin() function
 Returns the arg sine of the  x ,in radians
Syntex
asin(x)
Example
Output
The arg sine of 2 : 0.523598775598
The arg sine of -1 : -1.57079632679
The arg sine of 1 : 1.57079632679
The arg sine of 0 : 0.0
5. acos() function
 Returns the arg cosine of the  x ,in radians
Syntex
acos(x)
Example
Output
The arg cosine of 2 : 1.0471975512
The arg cosine of -1 : 3.14159265359
The arg cosine of 1 : 0.0
The arg cosine of 0 : 1.57079632679
6. atan() function
 Returns the arg cosine of the  x ,in radians
Syntex
acos(x)
Example

Output

The arg tangent of 2 : 0.463647609001
The arg tangent of -1 : -0.785398163397
The arg tangent of 1 : 0.785398163397
The arg tangent of 0 : 0.0
The arg tangent of 0 : 1.4711276743

Hyperbolic functions              

1. acosh(x) function
Return the inverse hyperbolic cosine of x

Syntex 

acosh(x)

Example

Output
acosh value of 1:  0.0
acosh value of 2:  1.31695789692
acosh value of pi/2:  1.02322747855

2. asinh(x)
Return the inverse hyperbolic sine of x

Syntex 

asinh(x)

Example

Output
asinh value of 0.5:  0.48121182506
asinh value of 0.65:  0.611224313763
asinh value of 0.85:  0.77123743336

 

3. atanh(x)
Return the inverse hyperbolic tangent of x

Syntex 

atanh(x)

Example

Output
atanh value of 0.5:  0.549306144334
atanh value of 0.65:  0.775298706206
atanh value of 0.85:  1.25615281199

 

4. cosh(x)
Return the hyperbolic cosine of x

Syntex 

cosh(x)

Example

cosh value of 1:  1.54308063482
cosh value of -1:  1.54308063482
cosh value of 2:  3.76219569108

 

5. sinh(x)
Return the hyperbolic sine of x

Syntex 

sinh(x)

Example

sinh value of 1:  1.17520119364
sinh value of -1:  -1.17520119364
sinh value of 2:  3.62686040785

6. tanh(x)
Return the hyperbolic tangent of x

Syntex 

tanh(x)

Example

Output
tanh value of 1:  0.761594155956
tanh value of -1:  -0.761594155956
tanh value of 2:  0.964027580076

 

 
 
 
 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes