Series

The code below sums the $1/n$ series, starting from the biggest and smallest number. In ideal world the result should be the same and should not saturate, here the series “converge”. Takes a while to run.

\% This is sum file
\% OK?
\%Partial Sum
\%S1=1+1/2+1/3+...+1/N, N=10 to the power k
\%S2=1/N+...+1/3+1/2+1, N=10 th the power k
\%Compares the two
 x kmax=10;
 clear x;
x=[];
format long e;
for k=1:kmax
n=10 ^ k
s1=0;s2=0;
for p=1:n
s1=s1+1/p;
s2=s2+1/(n-p+1);
end
x=[x;n,s1,s2,s1-s2]
end
disp(x);