%% Exercise 2 from Programming Tutorial I: % By: Grady Wright % % Date: January 26, 2012 %% Exercise 2 % We need to compute the following sum for different values of $N$ % % $$ \pi = 4\sum_{k=0}^N \frac{(-1)^k}{2k+1} $$. % % Here is the program: N = 10; mysum = 0; for k=0:N mysum = mysum + (-1)^k/(2*k+1); end mysum = 4*mysum; disp(['With N=' num2str(N) ' pi is approximately ' num2str(mysum)]);