Question: Bug in the series expansion of cosinus

Hi, the following Maple code produces an error for the value x=0: 0 instead of 1.

 

> for x from 0 to 5 do 

>print(evalf(sum((-1)^k*x^(2*k)/factorial(2*k), k = 0 .. 10)), evalf(cos(x))) 

> end do; 

0., 1. 
0.5403023059, 0.5403023059 
-0.4161468365, -0.4161468365 
-0.9899924966, -0.9899924966 
-0.6536436057, -0.6536436209 
0.2836642141, 0.2836621855 

Why such an error?

My solution to obtain the good value is:

> for x from 0 to 5 do 

> print(evalf(subs(y=x,sum((-1)^k*y^(2*k)/factorial(2*k), k = 0 .. 10))), evalf(cos(x))) 

> end do; 
                                1., 1. 


                      0.5403023059, 0.5403023059 


                     -0.4161468365, -0.4161468365 


                     -0.9899924966, -0.9899924966 


                     -0.6536436057, -0.6536436209 


                      0.2836642141, 0.2836621855 

Thanks.

Please Wait...