+ 1
How to find the sum of the series which has + and - alternately? For eg: 1-x^2/2+x^3/3-x^4/4+x^5/5...
Sum of series in C++
4 Answers
+ 2
Actually the sign can just be (-1)^n where n starts from 0.
+ 1
What Gordie said, and also...
Be aware that the order of computation will effect floating point arithmetic errors differently. You will want to experiment to find the least amount of error.
What Every Computer Scientist Should Know About Floating Point Arithmetic:
http://www.itu.dk/~sestoft/bachelor/IEEE754_article.pdf
Also check out:
https://stackoverflow.com/questions/6699066/in-which-order-should-floats-be-added-to-get-the-most-precise-result?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
+ 1
Also, did you unintentionally miss out the x ^ 1 term?
i.e. was it supposed to be:
1 - x + (x ^ 2 / 2) - (x ^ 3 / 3) etc
?
+ 1
ln(1 + x) = x - (x ^ 2 / 2) + (x ^ 3 / 3) etc
Source: http://mathworld.wolfram.com/MaclaurinSeries.html
So your series is just:
ln(1 + x) - x + 1