f(x)= x x^3/3+x^5/5+...+(- 1)^k * x^(2k+ 1)/(2k+ 1)+ ...
When |x| > is in 1, the absolute value of the series diverges, so it cannot be directly calculated by Euler formula. Therefore, the following formula can be used.
Calculation after equivalent conversion.
Equivalent conversion formula:
a) ATan( 1/x) = Pi/2 - ATan(x)
B) Atan (-x) =-Atan (x)
exceptional case
0 = arctangent (0)
Pi/2 = arctangent (infinity)
//
//Euler formula
//
// sum is the sum, $ term is the general item value, and j $ TERM is 1 at first, and then 1 is added. Wrksp is the work unit, depending on J. $ jterm' s
//depends on the maximum value.
//
void eul sum(int & amp; nterm,double *sum,double term,int jterm,double wrksp[])
{
Double tmp, dum
if(jterm == 1)
{
nterm = 1;
wrk sp[ 1]= term;
* sum = 0.5 * term
}
other
{
tmp = wrk sp[ 1];
wrk sp[ 1]= term;
for(int j = 1; j & lt= ntermj++)
{
dum = wrk sp[j+ 1];
wrk sp[j+ 1]= 0.5 *(wrk sp[j]+tmp);
tmp = dum
}
if(fabs(wrk sp[nterm+ 1])& lt; = fabs(wrksp[nterm]))
{
* sum = * sum+0.5 * wrk sp[nterm+ 1];
nterm = nterm+ 1;
}
other
{
* sum = * sum+wrk sp[nterm+ 1];
}
}
}
I don't need to give the code of series calculation.