How to Design Programs: An Introduction to Programming and Computing

Info icon This preview shows pages 1–3. Sign up to view the full content.

How to Design Programs: An Introduction to Computing and Programming [Go to first , previous , next page; contents ; index ] Section 23 Mathematical Examples Applying mathematics to real-world problems requires programs that implement mathematical functions. In many cases, the programs also employ functions that consume and produce functions. Mathematics is therefore a great starting point for practicing programming with functions and, more generally, for creating abstract functions. The first subsection covers sequences and series, a key element of mathematics. The second section discusses integration, which relies heavily on series. Finally, the third section introduces function differentiation. 23.1 Sequences and Series In pre-algebra and algebra, we encounter sequences (also known as progressions) of numbers. Here are three examples: 1. 0, 2, 4, 6, 8; 2. 1, 3, 5, 7, 9; 3. 5, 10, 15, 20, 25. The first two enumerate the first five even and odd natural numbers, respectively; the last one lists the first five positive integers, evenly divisible by 5. Sequences can also be infinite: 1. 0, 2, 4, 6, 8, ... ; 2. 1, 3, 5, 7, 9, ... ; 3. 5, 10, 15, 20, 25, ... Following mathematical tradition, infinite sequences end in `` ... '' and the reader must determine how to find more of the terms in the sequence. One way to understand sequences of numbers, especially infinite ones, is to match them up with an enumeration of the natural numbers. For example, the even and odd (natural) numbers match up like this: [curriculum3a-Z-G-2.gif] It is easy to see from this table that every even number is 2 · i for its index i and that an odd number is 2 · i + 1. Both statements can be translated into simple Scheme functions: (1 of 13) [2/5/2008 4:51:10 PM]
Image of page 1

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