我必须计算 的值arctan(x)
。我通过评估以下系列计算了这个值:
反正切 (x) = x – x^3/3 + x^5/5 – x^7/7 + x^9/9 - ...</p>
但是下面的代码无法计算出实际值。例如,calculate_angle(1)
返回 38.34 。为什么?
const double DEGREES_PER_RADIAN = 57.296;
double calculate_angle(double x)
{
int power=5,count=3;
double term,result,prev_res;
prev_res = x;
result= x-pow(x,3)/3;
while(abs(result-prev_res)<1e-10)
{
term = pow(x,power)/power;
if(count%2==0)
term = term*(-1);
prev_res=result;
result=result+term;
++count;
power+=2;
// if(count=99)
// break;
}
return result*DEGREES_PER_RADIAN;
}