问题描述
sympy 中的 cosd
、sind
似乎没有等价物(即以度为单位的参数的余弦和正弦).有什么简单的方法可以实现这些功能吗?
There seems to be no equivalent for cosd
, sind
in sympy (ie cosine and sine for arguments in degrees). Is there any simple way to implement those functions ?
对于 numpy,我做到了:
For numpy, I did :
numpy.cosd = lambda x : numpy.cos( numpy.deg2rad(x) )
类似:
sympy.cosd = lambda x : sympy.cos( sympy.pi/180*x )
适用于计算,但表达式打印为:
works for evaluation, but the expression is printed as :
cos(pi*x/180)
这不利于可读性(由于 3D 坐标变化,我的表达式很复杂).有没有办法创建一个 sympy.cosd
函数来计算 cos(pi/180 * x)
但打印 cosd(x)
?
which is not great for readability (I have complicated expression due to 3D coordinates changes). Is there any way to create a sympy.cosd
function which evaluates cos(pi/180 * x)
but prints cosd(x)
?
推荐答案
sympy
确实有一个 弧度转换器,在 mpmath
模块中.
sympy
does have a radian converter, in the mpmath
module.
sympy.cosd = lambda x : sympy.cos( sympy.mpmath.radians(x) )
这篇关于cosd 和 sind 同情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!