matlab cosd符号表达式,c等於matlab的sind和cosd函數。

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.

所以我正在使用一些matlab代碼,手工轉換成c代碼。我只是想知道是否有一個c等價於我在matlab代碼中看到的sind和cosd函數。我想這個答案會用角度來回答,而不是c sin和cos函數給出的結果是弧度。我想我可以把結果乘以180/,但是我想知道在數學中是否有一個庫函數。我沒有看到。或者,即使在gsl圖書館里有什么東西能做到這一點。

5 个解决方案

#1

9

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:

由於M_PI的不精確,H2CO3的解決方案將會對大參數造成災難性的損失。一般的、安全的說法是:

#define sind(x) (sin(fmod((x),360) * M_PI / 180))

#2

3

No, the trigonometric functions in the C standard library all work in radians. But you can easily get away with a macro or an inline function:

不,C標准庫中的三角函數都用弧度表示。但是,您可以輕松地使用宏或內聯函數獲得:

#define sind(x) (sin((x) * M_PI / 180))

or

inline double sind(double x)

{

return sin(x * M_PI / 180);

}

Note that the opposite of the conversion is needed when you want to alter the return value of the function (the so-called inverse or "arcus" functions):

請注意,當您想要更改函數的返回值時(即所謂的逆函數或“arcus”函數),則需要進行反向轉換:

inline double asind(double x)

{

return asin(x) / M_PI * 180;

}

#3

1

No, they are not available in C library. You will only find radian value arguments or return values in C library.

不,他們不在C圖書館。您只會在C庫中找到radian值參數或返回值。

#4

1

Also, note that sind and cosd etc do not return a result in degrees, they take their arguments in degrees. It is asind and acosd that return their results in degrees.

同時,注意sind和cosd等不返回一個結果,他們把他們的論點,在程度上。它是asind和acosd,它們返回結果的角度。

#5

0

Not in the C library. All trigonometric C library functions take arguments as radian values not degree. As you said you need to perform the conversion yourself or use a dedicated library.

不是在C圖書館。所有的三角函數庫函數都將參數作為radian值而不是degree。正如您所說,您需要自己執行轉換或使用專用的庫。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值