Sum of alternating series using four-digit chopping arithmetic

Click For Summary
The discussion focuses on calculating the sum of an alternating series using four-digit chopping arithmetic, specifically the series \(\sum_{n=0}^\infty \frac{(-1)^n}{(2n)!}\). Participants suggest methods for determining the appropriate value of n to avoid truncation errors, with one proposing to compute terms in pairs to maintain precision. A MATLAB function is provided to simulate four-digit chopping arithmetic, and the importance of nesting calculations to reduce roundoff errors is emphasized. Ultimately, the calculated sum is found to be approximately 0.5403, which aligns with the Maclaurin series approximation for cos(1).
drawar
Messages
130
Reaction score
0

Homework Statement


Let a_{n} be an alternating series whose terms are decreasing in magnitude. How to compute the sum as precisely as possible using four-digit chopping arithmetic? In particular, apply the method to compute \sum\limits_{n = 0}^\infty {\frac{{{{( - 1)}^n}}}{{(2n)!}}} and specify how the term \frac{{{{( - 1)}^n}}}{{(2n)!}} is obtained.Here is an excerpt from my textbook regarding the definition of finite digit chopping arithmetic:

Any positive real number y can be written in decimal floating point form: y=0.{d_1}{d_2}{d_3}...{d_k}{d_{k + 1}}{d_{k + 2}}... \times {10^n} where each digit d_{k} satises 0 \leq d_{k} \leq 9 and d_{1} \neq 0. To put y to a k-digit decimal floating point number, the first method is chopping (a.k.a. rounding towards 0 or truncation): fl(y)=0.{d_1}{d_2}{d_3}...{d_k} \times {10^n}
Here, fl(y) denotes the floating form of y.

Homework Equations


The Attempt at a Solution


I was told that calculating by nesting is more precise than calculating term by term, but how to calculate the sum of a series going to infinity? Any hint given is much appreciated, thanks!
 
Last edited:
Physics news on Phys.org
I suggest working backwards from some value of n, and considering each term as a fraction of the one to the left.
E.g. for the target series, one term is -1/2n times the one to the left. So you could start with the max n that gives a nonzero value in four decimal digits. Then add 1, to represent the term to the left, then multiply by -1/(2n-2) to get it relative to the next term to the left, and so on. I.e the sum is
1 +(-1/2)(1+(-1/4)(1+(-1/6)(1+...
 
Last edited:
haruspex said:
I suggest working backwards from some value of n, and considering each term as a fraction of the one to the left.
E.g. for the target series, one term is -1/2n times the one to the left. So you could start with the max n that gives a nonzero value in four decimal digits. Then add 1, to represent the term to the left, then multiply by -1/(2n-2) to get it relative to the next term to the left, and so on. I.e the sum is
1 +(-1/2)(1+(-1/4)(1+(-1/6)(1+...

haruspex said:
So you could start with the max n that gives a nonzero value in four decimal digits

Oh, that solved the infinity problem, but how do we come up with such n? I was given a function to simulate the 4-digit chopping arithmetic in MATLAB:
function y=fl(x)
if x==0.0,
y=0.0;
return
end
c=floor(log10(abs(x)))-3;
y=fix(x*10^(-c))*10^c;
return

As for the sum, should it be:
- \frac{1}{2}\left( {1 - \frac{1}{{12}}\left( {1 - \frac{1}{{30}}\left( {1 - \frac{1}{{56}}\left( {1 - ...} \right)} \right)} \right)} \right)?

Thanks!
 
If possible for a given series, I would suggest calculating the the series in pairs, positive and negative, so that you don't lose precision in the subtraction.

This method is possible and somewhat useful for this particular series but the terms decrease too fast to show this to its best advantage.
 
Joffan said:
If possible for a given series, I would suggest calculating the the series in pairs, positive and negative, so that you don't lose precision in the subtraction.

This method is possible and somewhat useful for this particular series but the terms decrease too fast to show this to its best advantage.

Thanks but I don't think that method gives a better accuracy than nested polynomials. For example, to calculate y = a + bx + c{x^2} + d{x^3}, one has to do 6 multiplications and 3 additions (assuming that the powers of x are calculated separately), while nesting it to y = a + x(b + x(c + dx)) requires only 3 multiplications and 3 additions. Less computations mean less roundoff errors and thus increasing the accuracy.
 
drawar said:
Oh, that solved the infinity problem, but how do we come up with such n? I was given a function to simulate the 4-digit chopping arithmetic in MATLAB:

As for the sum, should it be:
- \frac{1}{2}\left( {1 - \frac{1}{{12}}\left( {1 - \frac{1}{{30}}\left( {1 - \frac{1}{{56}}\left( {1 - ...} \right)} \right)} \right)} \right)?
What's the ratio between consecutive terms? That will tell what to put in the nesting. You want to start with the largest n for which the ratio doesn't truncate to zero in four digits.
 
haruspex said:
What's the ratio between consecutive terms? That will tell what to put in the nesting. You want to start with the largest n for which the ratio doesn't truncate to zero in four digits.

Ah thanks, I've figure it out already. n is 86 and the sum is 0.5403. Actually the sum is approximated by Maclaurin's series to be cos(1). :)
 

Similar threads

Replies
14
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 17 ·
Replies
17
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K