如何用python表示三角函数如题,能不能

Python014

如何用python表示三角函数如题,能不能,第1张

Python编码下面的三角函数包括以下种类:

12345678910

acos(x)//返回x的反余弦弧度值。asin(x)//返回x的反正弦弧度值。atan(x)//返回x的反正切弧度值。atan2(y, x)//返回给定的 X 及 Y 坐标值的反正切值。cos(x)//返回x的弧度的余弦值。hypot(x, y)//返回欧几里德范数 sqrt(x*x + y*y)。sin(x)//返回的x弧度的正弦值。tan(x)//返回x弧度的正切值。degrees(x)//将弧度转换为角度,如degrees(math.pi/2) , 返回90.0radians(x)//将角度转换为弧度

下面介绍了Python计算三角函数之asin()方法的使用(其它只需替换上述方法即可),返回x的反正弦,以弧度表示,代码如下:

12345678910111213

#!/usr/bin/python import math print "asin(0.64) : ", math.asin(0.64) print "asin(0) : ", math.asin(0) print "asin(-1) : ", math.asin(-1) print "asin(1) : ", math.asin(1) #运行结果如下:asin(0.64) : 0.694498265627asin(0) : 0.0asin(-1) : -1.57079632679asin(1) : 1.57079632679

这篇文章主要介绍了Python中计算三角函数之cos()方法的使用简介,是Python入门的基础知识,需要的朋友可以参考下

cos()方法返回x弧度的余弦值。

语法

以下是cos()方法的语法:

cos(x)

注意:此函数是无法直接访问的,所以我们需要导入math模块,然后需要用math的静态对象来调用这个函数。

参数

x

--

这必须是一个数值

返回值

此方法返回-1

1之间的数值,它表示角度的余弦值

例子

下面的例子展示cos()方法的使用

?

1

2

3

4

5

6

7

8#!/usr/bin/python

import

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)

当我们运行上面的程序,它会产生以下结果:

?

1

2

3

4

5cos(3)

:

-0.9899924966

cos(-3)

:

-0.9899924966

cos(0)

:

1.0

cos(math.pi)

:

-1.0

cos(2*math.pi)

:

1.0

在python中,有一个math

module,你可以import

math,

里面有math.sin(),math.cos(),math.asin()和math.acos()四个函数.

有了这四个函数你就可以求函数值和角度了.

注意:括号里面填的数值,要用弧度制.