10.2 Infinite Series

The code below computes and plots the first 20 terms and the first 20 partial sums of the series ${\displaystyle \sum_{n=1}^\infty \frac{1}{n^2}}$. The terms are plotted as red dots, the partial sums as blue asterisks.

>> n = 1:20; >> a = 1./n.^2; >> for j=1:20; s(j)=sum( a(1:j) ); end >> plot( a, '.r' ) >> hold on >> plot( s, '*b' )