mydy.net
当前位置:首页 >> 如何用C语言编程Cos x >>

如何用C语言编程Cos x

/*利用泰勒展式近似求cos(x)的值*/#include<stdio.h>#define E 1e-10//精度要求int main(){ double x; double cos(double x); printf("please input an radian:"); scanf("%lf",&x); printf("cos (%lf)=%.16lf\n",x,cos(x)); return 0;}/*泰勒展式cos(x) = x^0

对于sn=cosx+cos2x+cos3x+……+cosnx,有:2sin(x/2)[cosx+cos2x+cos3x+……+cosnx ]=2sin(x/2)cosx+2sin(x/2)cos2x+2sin(x/2)cos3x+……+2sin(x/2)cosnx=sin(3x/2)-sin(x/2)+sin(5x/2)-sin(3x/2)+sin(7x/2)-sin(5x/2)+……+sin(x/2+nx)-sin(nx-x/2)=

你的程序没有注释,这是编程的大忌,让人无从测试 我没有认真看过你的程序,我很 仓促的写了下我的程序,虽然有很很多漏洞,但也许可以帮助你理解这种求近似值的算法#include #include long jiecheng(int x);//递归求阶乘 main() { double x;

#include#includedouble myfx(){ double i=1.0,l=0.0,r=1.0,t; i=(l+r)/2.0; t=(cos(i)-i); while(1) { t=(cos(i)-i); if(abs(t)0) { l=i; i=(l+r)/2.0; } else { r=i; i=(l+r)/2.0; } } printf("%f %f\n",i,t); return i;}void main(){ float t=myfx(); printf("%f\n",t);}该函数单调递减,f(x)=cosx-xf(0)>0 f(1) 评论0 0 0

-1=解在-1=#includevoid main(){double x;for(x=-1;x精确到10的-6次方所以用1e-7但最终只精确到10的-6次方所以用1e-6较好但一定要1e-7也能用

cos函数的输入值为弧度,也就是将cos函数后加上弧度,然后就可以得到想要的结果.我们需要把度化为弧度:假设度数为d,则对应的弧度为:d * pi / 180

题目所说的“当取8位小数时,结果约为1.86602621”有误.经用WINDOWS计算器验证,程序的计算是正确的.输出的第一行是验证用的,可以删除. #include<stdio.h>#include<math.h>double mycos(double x){double y=1,t=1,p; p=3.

#include <stdio.h>#include "math.h" void main() { int n=1; double x; printf("输入x:"); scanf("%lf",&x); while(pow(x,n)-pow(x,n+1)>=1e-7) { n++; } printf("%d:%.9lf,%d:%.9lf\n",n,pow(x,n),n+1,pow(x,n+1)); }

x -- 用弧度值输入 精度 -- 1E-07 泰勒公式:cos(x) = 1 - x^2/2! + x^4/4! - x^6/6! 程序:#include<stdio.h>#include<math.h> void main(){ double x,term,sum,x2; int i; printf("input x in HuDu\n"); scanf("%lf",&x); x2 = x * x; sum = 1.0; term = 1.0; for

#include<math.h>#include<stdio.h>void main() { int n=2; float x; double sum=1.0,term=1.0; printf("input x:"); scanf("%f",&x); do { term=-term*x*x/(n*(n-1)); sum+=term; n=n+2; } while (fabs(term)>=1e-5); printf("cos(%g)=%.5f\n",x,sum);}

网站首页 | 网站地图
All rights reserved Powered by www.mydy.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com