bycj.net
当前位置:首页 >> C语言求余弦函数近似值,输入精度E,用下列公式求C... >>

C语言求余弦函数近似值,输入精度E,用下列公式求C...

#include<stdio.h>#include<math.h> double funcos (double e,double x); int main(void) { double e,pi,x; printf("输入e和x:"); scanf("%lf%lf",&e,&x); pi=funcos(e,x); printf("%lf",pi); return 0; } double funcos (double e,double x) { double sum=0,i=1

double funcos(double e,double x){ double cos=0;t=x; int n=1,f=1; while(t>e){ cos += f*t; t *= (x*x/n/(n+1); n += 2; f=-f; }}

这是利用泰勒公式求于心函数的近似值,是一个交错级数,只要某一项小于给定精度,以后所有想的和也小于给定精度,展式的规律很明显,正负交错,分子乘方次数递增

#include using namespace std; double funCos(double e, float x) { int i, m, n, p; i = 2; m = x; n = 1; p = -1; double s = 1.0, sum; sum = 1; while (s > e) { m = 1; for (int j = 1; j { m = m*x; } n = 1; for (int k = 1; k { n = n*k; } sum = sum + p*(m / n); s = (m / n);

double funcos(double e, double x) { if(e>0) { int i=0; double item=1; double cosx=0; while(fabs(item)>=e) { cosx+=item; i++; item*=-1*x*x/(2*i*(2*i-1)) } return cosx; } else return -2; }

#include#includedouble funcos(double x,double e);int main(void){double n,x,e;scanf("e: %lf%*c",&e);scanf("x: %lf%*c",&x);n=funcos(x,e);printf("cos(x)=%.3lf",n);return 0;}double funcos(double x,double e){ int i,k,flag=1; double sum,result=0,fact=1; for(i=0;;i+=2){ sum=x ; fact=1; for(k=1;k 评论0 0 0

不知道题目的目的是考读写格式还是计算.假定是计算,程序如下:#include <stdio.h>#include <stdlib.h> #include <math.h> double funcos(double e,double x){ double sum=1.0,term=1; int i2=0,x2; while(1){ term= (-1) * term*x/(i2+1) *x /(i2+2); sum=

cos(x)为什么变成cosx(x)??还有,能点明一下问题么?谢谢!!

pow(x,y) 要求x>0,所以pow(-1,a/2)是错的其实,符号用 k=k*(-1)就可以控制;x^n/n!=x^(n-2)*x*畅储扳肥殖堵帮瑟爆鸡x/((n-2)!*(n-1)*n)也就是利用前项的结果就可以求,不需要每次分别求

这个是用N阶麦克劳林公式求函数值,我马上帮你写.麻烦采纳,谢谢!

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