一个数学函数题,想不明白?
已知y=f(x,n)/(f(x+2.3,n)+f(x-3.2,n+3)),其中f(x,n)=1-x*x/2!+x*x*x*x/4!...+(-1)的n次方*x的2n次方/(2n)! (n>=0)当x=5.6,n=7时,求y的值。 题目给出y=-0.074521, 但是运行结果却是y=-0.182564
#include<stdio.h>
double f(double x,unsigned n)
{ unsigned i,j,k;
double p,s,sum,flag;
flag=-1.0;
if(n>0) {
sum=p=s=1.0;
for(k=1;k<=n;k++){
for(j=1;j<=2*k;j++)
s*=x;
for(i=1;i<=2*k;i++)
p*=i;
sum+=flag*s/p;
flag=-flag;
}
return sum;
}
else return 1;
}
int main()
{ double x,y;
unsigned n;
printf("input x=");
scanf("%f",&x);
printf("input n=");
scanf("%u",&n);
y=f(x,n)/(f(x+2.3,n)+f(x-3.2,n+3));
printf("y=%.6f\n",y);
return 0;
}
哪位大侠知道是为什么么?