温馨提示×

如何在python中使用三角函数

九三
2670
2021-01-28 19:09:50
栏目: 编程语言

如何在python中使用三角函数

python中使用三角函数的方法

1.正弦函数

python中的正弦函数是sin()函数,其作用是返回的x弧度的正弦值。

sin()函数语法:

math.sin(x)

sin()函数使用方法:

import math #导入math模块

print "sin(3) : ", math.sin(3)

print "sin(-3) : ", math.sin(-3)

print "sin(0) : ", math.sin(0)

print "sin(math.pi) : ", math.sin(math.pi)

print "sin(math.pi/2) : ", math.sin(math.pi/2)

2.余弦函数

python中的cos()函数,其作用是返回x的弧度的余弦值。

cos()函数语法:

math.cos(x)

cos()函数使用方法:

import math #导入math模块

print "cos(3) : ", math.cos(3)

print "cos(-3) : ", math.cos(-3)

print "cos(0) : ", math.cos(0)

print "cos(math.pi) : ", math.cos(math.pi)

print "cos(2*math.pi) : ", math.cos(2*math.pi)

3.正切函数

python中的正切函数是tan()函数,其作用是返回x弧度的正切值。

tan()函数语法:

math.tan(x)

tan()函数使用方法:

import math #导入math模块

print "tan(3) : ", math.tan(3)

print "tan(-3) : ", math.tan(-3)

print "tan(0) : ", math.tan(0)

print "tan(math.pi) : ", math.tan(math.pi)

print "tan(math.pi/2) : ", math.tan(math.pi/2)

print "tan(math.pi/4) : ", math.tan(math.pi/4)

0