新聞中心
如何用C語言中專門的數(shù)學(xué)算法實現(xiàn)正弦,余弦函數(shù)的計算
頭文件包含。math.h
創(chuàng)新互聯(lián)公司是一家專注于網(wǎng)站設(shè)計制作、成都網(wǎng)站制作與策劃設(shè)計,晉州網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)10余年,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:晉州等地區(qū)。晉州做網(wǎng)站價格咨詢:028-86922220
cos
:余弦函數(shù)
函數(shù)原型:double
cos(double
x);
頭文件:#includemath.h
是否是標準函數(shù):是
函數(shù)功能:求x的余弦值,這里,x為弧度。
返回值:計算結(jié)果的雙精度值帆禪襲。
例程如下:
求cosx。
#include
stdio.h
#include
math.h
int
main(void)
{
double
result;
double
x
=
M_PI;
result
=
cos(x);
printf("cos(PI)
is
%lf\n",
result);
return
0;
}
sin:正弦函數(shù)
函數(shù)襲渣原型:double
sin(double
x);
頭文件:#includemath.h
是否是標準函數(shù):是
函數(shù)功能:求x的正弦值態(tài)兄,這里,x為弧度。
返回值:計算結(jié)果的雙精度值。
例程如下:
求sinx。
#include
stdio.h
#include
math.h
int
main(void)
{
float
x;
x=M_PI/2;
printf("sin(PI/2)=%f",sin(x));
getchar();
return
0;
}
對sin函數(shù)求積分,用C語言如何實現(xiàn)???
??
解法一 ∫sin(x)dx = cos(x) +c 積侍殲姿分公式
double jfSin(double x, double y)
{
return cos(y) - cos(x)
}
解改鄭法二 野蠻近似法
d是精老絕度
double jfSin(double x, double y, double dx)
{ double ret;
for(; x =y; x+= dx)
{
ret += sin(x);
}
return ret;
}
C語言編程求函數(shù)y=sinx在(0,1)區(qū)間的定積分?
#includestdio.h
#include前信伍math.h
#define N 10000000
void main()
{
double sum=0;
int i;
for(i=0; iN; i++)
{
sum += sin((double)(i)/N)/N;
}
printf("%lf\慧或n%lf",sum,1-cos(1));
}
N后面的0有點多了,不坦納過這個數(shù)剛好能精確到小數(shù)點后6位。
當(dāng)然,這個程序的算法實在是太垃圾了,效率非常的低下……
名稱欄目:c語言求余弦函數(shù)定積分 c語言實驗題余弦
網(wǎng)頁網(wǎng)址:http://ef60e0e.cn/article/ddpjdss.html