c等价于matlab的sind和cosd函数 [英] c equavilent to matlab's sind and cosd function
问题描述
因此,我正在处理一些将Matlab代码手动转换为C代码的问题.我只是想知道是否有一个C等于我在matlab代码中看到的sind和cosd函数.我猜这返回的是度数的答案,而不是给出弧度结果的c sin和cos函数.我想我可以将结果乘以180/pi,但只是想知道math.h中是否有库函数,所以我没有看到.或者即使gsl库中有执行此操作的文件.
So I am working with some matlab code converting to c code by hand. I am just wondering if there is a c equivalent to the sind and cosd functions I'm seeing in the matlab code. I guess this returns the answer in degrees rather than the c sin and cos function that gives the result in radians. I guess I could just multiply the result by 180/pi but was just wondering if there was a library function in math.h I'm not seeing. Or even if there is something in the gsl library that does that.
推荐答案
由于M_PI
的不精确性,对于大参数,H2CO3的解决方案将导致灾难性的精度损失.任何参数的通用安全版本是:
H2CO3's solution will have catastrophic loss of precision for large arguments due to the imprecision of M_PI
. The general, safe version for any argument is:
#define sind(x) (sin(fmod((x),360) * M_PI / 180))
这篇关于c等价于matlab的sind和cosd函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!