MATLAB中为什么用三角函数求弧度?

如题所述

主要是利用利用数学函数中的反三角函数。

1、头文件math.h中宏定义的是M_PI

#define M_PI 3.14159265358979323846

2、这是一个在库文件头文件math.h中的定义的宏,实际上就是圆周率π的一个近似值,约等于3.1415

下面是一个求三角函数sin(a)值的一个程序,这里就用到了M_PI这个宏。由于这里的a要求是弧度,所以对于输入的角的度数做了相应的转换。

#include <stdio.h>

#include <math.h>

int main()

{

int degree;

printf("Please input angle degree:\n");fflush(NULL);

scanf("%d",°ree);

printf("sin(%d)=%f\n",degree,sin(M_PI*degree/180));

return 0;

}

因为:头文件math.h中宏定义的是M_PI

扩展资料:

关于上述提到的M_PI

.M_PI 是一个宏定义,圆周率的定义

#define M_PI 3.14159265358979323846 

此宏定义和编译器有关,TC中M_PI宏就定义在<math.h>里面。

但vc的<math.h>中没有了M_PI的宏定义。

常见宏定义:

#include<bits/stdc++.h>

#define _USE_MATH_DEFINES

using namespace std;

int main()

{

cout<<M_PI<<endl;

cout<<M_E<<endl;

return 0;

}   

#if defined(_USE_MATH_DEFINES) && !defined(_MATH_DEFINES_DEFINED)

#define _MATH_DEFINES_DEFINED

#define M_E        2.71828182845904523536

#define M_LOG2E    1.44269504088896340736

#define M_LOG10E   0.434294481903251827651

#define M_LN2      0.693147180559945309417

#define M_LN10     2.30258509299404568402

#define M_PI       3.14159265358979323846

#define M_PI_2     1.57079632679489661923

#define M_PI_4     0.785398163397448309616

#define M_1_PI     0.318309886183790671538

#define M_2_PI     0.636619772367581343076

#define M_2_SQRTPI 1.12837916709551257390

#define M_SQRT2    1.41421356237309504880

#define M_SQRT1_2  0.707106781186547524401

#endif  /* _USE_MATH_DEFINES */

温馨提示:答案为网友推荐,仅供参考
相似回答