Find the sum of that alternating series given by 1 12 13
     Find the sum of that alternating series given by 1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 +... 
  
  Solution
The given series is known as the alternating harmonic series. In particular, the sum is equal to the natural logarithm of 2.
% our goal
 L = log(2)
% we try 5 terms
 n = 1 : 5
% define the alternating sequence
 seq = (-1).^(n+1) ./ n
% get the sum
 s = sum(seq)
The Matlab answer is:
L =     0.6931
 n =     1     2     3     4     5
  seq =   1.0000   -0.5000    0.3333   -0.2500    0.2000
  s =     0.7833
 We see that 5 terms are not enough. Let’s try 1000 terms.
% we try 1000 terms
 n = 1 : 1000;
% define the alternating sequence
 seq = (-1).^(n+1) ./ n;
% get the sum
 s = sum(seq)
The new answer is:
s = 0.6926
This is a closer answer, but we’re still far from log 2. More terms are needed for higher accuracy... be aware...

