chapter3 - Chapter 3 Sequences 3.1 Summation Nested loops,...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Chapter 3 Sequences 3.1 Summation Nested loops, while-loops with compound termination criteria 3.2 Recursions One-term recursion, searching for a first occurrence, two-term recursion. In Chapter 2 we played with the sequence of regular n-gon areas { a n } where A n = n 2 sin 2 n . We numerically discovered that lim n A n = , a fact that is consistent with our geometric intuition. In this chapter we build our n-th term expertise by exploring sequences that are specified in various ways. At the top of our agenda are sequences of sums like S n = 1 + 1 4 + 1 9 + + 1 n 2 . Many important functions can be approximated by very simple summations, e.g., exp( x ) 1 + x + x 2 2! + + x n n ! . The quality of the approximation depends upon the value of x and the integer n . Sometimes a sequence is defined recursively . The n-term may be specified as a function of previous terms, e.g., f n = 1 if n = 1 or 2 f n- 1 + f n- 2 if n 3 Sequence problems of this variety give us the opportunity to practice some difficult formula-to- program transitions. 75 76 Chapter 3. Sequences 3.1 Summation The summation of a sequence of regularly scheduled numbers is such a common enterprise that a special notation is used. This is the sigma notation and here is an example: n X k =0 x k k ! = 1 + x + x 2 2! + + x n n ! . The value of many regular summations is known. For example, the sum of the first n positive integers is given by n X k =1 k = n ( n + 1) 2 . (3.1.1) It is interesting to write programs that check rules like this. The program Example4 1 confirms that the sum of the first n integers is given by the above rule for n = 1 to 20. % Example3 1: Check the rule for the summation of the first n integers nmax= 20; % The no. of n-values used in the rule checking s= 0; % The sum of the sequence so far % Print the column headings fprintf( \ n); fprintf( \ n n \ t Sum \ t n(n+1)/2 \ n); fprintf(--------------------------- \ n); % Compute summation of first n integers for n= 1:nmax s= s+n; rhs= n*(n+1)/2; fprintf(%3d \ t %3d \ t %8d \ n, n, s, rhs); end Output: n Sum n(n+1)/2---------------- 1 1 1 2 3 3 3 6 6 . . . 19 190 190 20 210 210 The program uses a for-loop to actually compute the summation. The result is then printed side-by-side with the value of the summation formula. The program is not a proof of Equation 3.1. Summation 77 (3.1.1); it merely checks its correctness for a small set of possible n . Problem 3.1. Modify Example3 1 so that it confirms the following for n = 1 .. 20: n X k =1 k 2 = n ( n + 1)(2 n + 1) 6 . Problem 3.2. It is possible to find real numbers a, b, c, d, and e so that n X k =1 k 3 = an 4 + bn 3 + cn 2 + dn + e for all n . Note that if n is large enough, then n X k =1 k 3 an 4 ....
View Full Document

This note was uploaded on 09/23/2007 for the course COM S 100 taught by Professor Fan/chew during the Spring '07 term at Cornell University (Engineering School).

Page1 / 17

chapter3 - Chapter 3 Sequences 3.1 Summation Nested loops,...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online