Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In exact arithmetic, the partial sums S_N = sigma_k=1^N 1/k diverge as N rightar

ID: 3782544 • Letter: I

Question

In exact arithmetic, the partial sums S_N = sigma_k=1^N 1/k diverge as N rightarrow infinity. Write a program that keeps adding 1/k in single precision arithmetic (float. REAL*4) until the sum stays exactly the same. How can this happen? As a second exercise, consider the following reformulation of the problem: in exact arithmetic, the order in which we add up the numbers 1/k does not matter. Check what happens if your program computes the partial sums in groups of 10 terms at a time as follows: S_10N = sigma_j=0^n - 1 (sigma_k=1^10 1/10 j + k) where the terms in parentheses are added up first, before they are added to the global sum. Perform the outer summation until the value of the sum does not change anymore. Compare the result to what you got previously. Explain.

Explanation / Answer

Part 1)

So, basically questions asks us to add the terms untill the |sum_new - sum_previous| < 0.0001 (i.e real*4 means accuracy upto 4rth decimal point) So, when we add terms after k = 10000 to the series the change in overall sum is less than 0.0001, and hence we can stop the loop there when k = 10000.

Matlab code:

clc;
clear all;
Sn = 1.0;
N = 100000;
for k=2:N
k
Sn_prev = Sn;
Sn = Sn + (k)^(-1)
if((Sn - Sn_prev) < 0.0001)
break;
end
end

Part 2)

As we keep on adding new terms, the value of new term is not going to be exactly equal to 0, So we added the terms untill N = 1000000,and the final value of was S_10N = 16.6953. Previously we added the terms untill K = 10000 and obtained Sn = 9.7876.

Matlab Code:

clc;
clear all;
S_10n = 0.0;
N = 1000001;

for j = 0:N-1
j
tmp = 0.0;
for k = 1:10
tmp = tmp + (1/((10*j) + k));
end
S_10n = S_10n + tmp;   
if(tmp == 0.0)
S_10n
break;
end
end