Tan 1 trong Python

In Python, math module contains a number of mathematical operations, which can be performed with ease using the module. math.tan[] function returns the tangent of value passed as argument. The value passed in this function should be in radians.

Syntax: math.tan[x]

Parameter:
x : value to be passed to tan[]

Returns: Returns the tangent of value passed as argument

Code #1:




# Python code to demonstrate the working of tan[]

     

# importing "math" for mathematical operations 

import math 

    

a= math.pi# Python code to demonstrate the working of tan[]0 # Python code to demonstrate the working of tan[]1

     

# Python code to demonstrate the working of tan[]3

# Python code to demonstrate the working of tan[]4 # Python code to demonstrate the working of tan[]5# Python code to demonstrate the working of tan[]6# Python code to demonstrate the working of tan[]7=# Python code to demonstrate the working of tan[]9

# Python code to demonstrate the working of tan[]4     1

 
Code #2:




    2

    3

    4

import     6

import     8

import # importing "math" for mathematical operations 0

# importing "math" for mathematical operations 

# importing "math" for mathematical operations 2= # importing "math" for mathematical operations 4# importing "math" for mathematical operations 5# importing "math" for mathematical operations 6# importing "math" for mathematical operations 7# importing "math" for mathematical operations 8

# importing "math" for mathematical operations 

import0= import2

# importing "math" for mathematical operations 

import4 import5import6 import7# Python code to demonstrate the working of tan[]5import9math 0

    math 2

    import5math 5= math 7

# importing "math" for mathematical operations 

math 

# Python code to demonstrate the working of tan[]4# Python code to demonstrate the working of tan[]5   2   3

# Python code to demonstrate the working of tan[]4# Python code to demonstrate the working of tan[]5   6   7

# importing "math" for mathematical operations 

   9

a0= a2a3= a5# importing "math" for mathematical operations 8

a7a8# importing "math" for mathematical operations 8

=0=1# importing "math" for mathematical operations 8

=3=4# importing "math" for mathematical operations 8

=6

Output:

in_array : [0. 0.34906585 0.6981317 1.04719755 1.3962634 1.74532925
2.0943951 2.44346095 2.7925268 3.14159265]

out_array : [0.0, 0.36397023426620234, 0.8390996311772799, 1.7320508075688767, 5.671281819617707, -5.671281819617711, -1.7320508075688783, -0.8390996311772804, -0.36397023426620256, -1.2246467991473532e-16]

1. Hàm sin[]: Hàm này trả về giá trị sine của đối số được truyền vào hàm. Đối số được truyền vào cho hàm này phải ở dạng radian.

2. Hàm cos[]: Hàm này trả về giá trị cosine của đối số được truyền vào hàm. Đối số được truyền vào cho hàm này phải ở dạng radian.

Dưới đây là ví dụ mô tả cách thức hoạt động của hàm sin[] và hàm cos[]:


# Python code to demonstrate the working of 
# sin[] and cos[] 
   
# importing "math" for mathematical operations 
import math 
  
a = math.pi/6
   
# returning the value of sine of pi/6 
print ["The value of sine of pi/6 is : ", end=""] 
print [math.sin[a]] 
   
# returning the value of cosine of pi/6 
print ["The value of cosine of pi/6 is : ", end=""] 
print [math.cos[a]] 

Kết quả in ra là:

The value of sine of pi/6 is : 0.49999999999999994
The value of cosine of pi/6 is : 0.8660254037844387

3. Hàm tan[]: Hàm này trả về giá trị tangent của đối số được truyền vào hàm. Đối số được truyền vào cho hàm này phải ở dạng radian.

4. Hàm hypot[a, b]: Hàm này trả về giá trị của cạnh huyền – hypotenuse của hai đối số được truyền vào hàm. Về mặt số học, hàm này sẽ trả về giá trị của phép tính sqrt[a*a + b*b].

Dưới đây là ví dụ mô tả cách thức hoạt động của hàm tan[] và hàm hypot[]:


# Python code to demonstrate the working of 
# tan[] and hypot[] 
   
# importing "math" for mathematical operations 
import math 
  
a = math.pi/6
b = 3
c = 4
   
# returning the value of tangent of pi/6 
print ["The value of tangent of pi/6 is : ", end=""] 
print [math.tan[a]] 
   
# returning the value of hypotenuse of 3 and 4 
print ["The value of hypotenuse of 3 and 4 is : ", end=""] 
print [math.hypot[b,c]] 

Kết quả in ra là:

The value of tangent of pi/6 is : 0.5773502691896257
The value of hypotenuse of 3 and 4 is : 5.0

5. Hàm degrees[]: Hàm này được sử dụng để chuyển đổi giá trị của đối số được truyền vào hàm từ radian thành độ.

6. Hàm radians[]: Hàm này được sử dụng để chuyển đổi giá trị của đối số được truyền vào hàm từ độ thành radian.

Dưới đây là ví dụ mô tả cách thức hoạt động của hàm degrees[] và hàm radians[]:

# -----------------------------------------------------------
#Cafedev.vn - Kênh thông tin IT hàng đầu Việt Nam
#@author cafedevn
#Contact: cafedevn@gmail.com
#Fanpage: //www.facebook.com/cafedevn
#Group: //www.facebook.com/groups/cafedev.vn/
#Instagram: //instagram.com/cafedevn
#Twitter: //twitter.com/CafedeVn
#Linkedin: //www.linkedin.com/in/cafe-dev-407054199/
#Pinterest: //www.pinterest.com/cafedevvn/
#YouTube: //www.youtube.com/channel/UCE7zpY_SlHGEgo67pHxqIoA/
# -----------------------------------------------------------

# Python code to demonstrate the working of 
# degrees[] and radians[] 
   
# importing "math" for mathematical operations 
import math 
   
a = math.pi/6
b = 30
  
# returning the converted value from radians to degrees 
print ["The converted value from radians to degrees is : ", end=""] 
print [math.degrees[a]] 
   
# returning the converted value from degrees to radians 
print ["The converted value from degrees to radians is : ", end=""] 
print [math.radians[b]

Kết quả in ra là:

The converted value from radians to degrees is : 29.999999999999996
The converted value from degrees to radians is : 0.5235987755982988

Nguồn và Tài liệu tiếng anh tham khảo:

  • w3school
  • python.org
  • geeksforgeeks

Tài liệu từ cafedev:

  • Full series tự học Python từ cơ bản tới nâng cao tại đây nha.
  • Ebook về python tại đây.
  • Các series tự học lập trình khác

Nếu bạn thấy hay và hữu ích, bạn có thể tham gia các kênh sau của cafedev để nhận được nhiều hơn nữa:

Chủ Đề