Bài này sẽ nói về các hàm lượng giác và hàm góc.

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: https://www.facebook.com/cafedevn
#Group: https://www.facebook.com/groups/cafedev.vn/
#Instagram: https://instagram.com/cafedevn
#Twitter: https://twitter.com/CafedeVn
#Linkedin: https://www.linkedin.com/in/cafe-dev-407054199/
#Pinterest: https://www.pinterest.com/cafedevvn/
#YouTube: https://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:

Tài liệu từ cafedev:

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ào thân ái và quyết thắng!

Đăng ký kênh youtube để ủng hộ Cafedev nha các bạn, Thanks you!