Math functions in ‘math’ module -II

             Basic mathematical functions in math module are explained in part1 post.

https://www.blogger.com/blog/post/edit/5251857942821229/5740320177801086000.

Remaining mathematical functions are explained in this blog post.

Trigonometry functions in ‘math’ module:

            Trigonometry is a field of mathematics which deals with angles. To measure angles, radian and degree are used. In ‘math’ module, there are two functions to convert radian to degree and degree to radian.

#import the math module

import math

#get the input of degree value and store as integer in ‘de’

de = int(input("Enter the degree value"))

#print the converted radian value

print(math.radians(de))

#get the input value as float and store it as float in ‘ra’

ra = float(input("Enter the radian value"))

#print the degree value

print(math.degrees(ra))

Output:

Some of the other functions are…

Sin(),cos(),tan(),sinh(),cosh(),tanh(). These built in functions are used in below program.

#import the math module.

import math

#print the sin,cos,tan,sinh,cosh,tanh values.

print(math.sin(90))

print(math.cos(30))

print(math.tan(45))

print(math.sinh(60))

print(math.cosh(90))

print(math.tanh(90))

when executing this program, user gets the below output.

Log functions in ‘math’ module:

It is the inverse function of exponentiation. The below program uses the built in log functions.

Here, log() gives the log value.

Log10() returns the log 10 value.

Log2() provides the log 2 value.

Log1p denotes log 1+p value.

#program to print log values

import math

#prints the log values of different base.

print(math.log(16))

print(math.log10(23))

print(math.log2(2))

print(math.log1p(34))

output:

These are various functions in ‘math’ built in module.

 

No comments:

Post a Comment