Xbee3 - 没有数学模块的三角函数值的计算

Xbee3 - Calculation of trigonometric values without math module

我在 Xbee3-24 上使用 MicroPython,它内部没有 math 模块。我需要计算 sincosarctan 值。

如何在不使用 math 模块的情况下使用三角函数?

您可以使用幂级数来近似 trigonometric functions and inverse trigonometric functions(以及大多数其他函数)。

例如,您可以定义一个近似计算 sin(x) 的函数:

def approx_sin(x):
    return x - (pow(x, 3)/6) + (pow(x, 5)/120) - (pow(x, 7)/5040)

-pi <= x <= pi 范围内的真实值的最大误差为 0.0752(在桌面上 Python 3.6)。如果您需要更高的准确性,请添加更多项 - 如果您需要处理超出该范围的 x,请先将其带入该范围。