Skip to main content
 首页 » 编程设计

python之python中三角函数的计算

2025年05月04日14shanyou

Python是如何计算三角函数的? 我尝试使用

x = ((0.1-0.001)/2)*math.sin(((1/20)*math.pi*20)+(0.5*math.pi*1))+((0.1-0.001)/2)+0.001 

我得到了

x = 0.1 

这是为什么呢?在通常的计算器(弧度)中,我得到 0.001

请您参考如下方法:

在Python 2中,/是整数除法,需要导入__future__ .division对于 float 除法:

>>> from __future__ import division 
>>> import math 
>>> x = ((0.1-0.001)/2)*math.sin(((1/20)*math.pi*20)+(0.5*math.pi*1))+((0.1-0.001)/2)+0.001 
>>> x 
0.001