I want to compute the cosine of 2.345 correct to 5 decimal places using Taylor series. My code is given below. I am not sure what is wrong with that. Any help is appreciated!
> x<-2.345
> count<-0
> repeat{
+ count<-count+1
+ initial = (-1)^(n-1)
+ numerator = x^(2*(n-1))
+ denominator = factorial(2*(n-1))
+ total=(initial*numerator)/denominator
+ if(abs((cos(x)-total)/cos(x))*100 <= 0.00001) break
+ sum=sum+total
+ }