[previous] [up] [next]     [index]
Next: The Area Under a Up: Geometric Sequences and Series Previous: Geometric Sequences and Series

Taylor Series

Mathematical constants like tex2html_wrap_inline71499 and e or functions like tex2html_wrap_inline72402 , tex2html_wrap_inline72404 , tex2html_wrap_inline72406 are difficult to compute. Since these functions are important for many daily engineering applications, mathematicians have spent a lot of time and energy looking for better ways to compute these functions. One method is to replace a function with its Taylor series, which is, roughly speaking, an infinitely long polynomial.

A Taylor series is the sum of a sequence of terms. In contrast to arithmetic or geometric sequences, the terms of a Taylor series depend on two unknowns: some variable x and the position i in the sequence. Here is the Taylor series for the exponential function:

displaymath72408

That is, if we wish to compute tex2html_wrap_inline72410 for any specific x, we replace x with the number and determine the value of the series. In other words, for a specific value of x, say, 1, the Taylor series becomes an ordinary series, that is, a sum of some sequence of numbers:

displaymath72416

While this series is the sum of an infinitely long sequence, it actually is a number, and it often suffices to add just a few of the first few terms to have an idea what the number is.

The key to computing a Taylor series is to formulate each term in the underlying sequence as a function of x and its position i. In our running example, the Taylor sequence for the exponential function has the shape

displaymath72418

Assuming a fixed x, here is an equivalent Scheme definition:

;; e-taylor : N -> number
(define (e-taylor i) 
  (/ (expt x i) (! i)))

;; ! : N -> number (define (! n) (cond [(= n 0) 1] [else (* n (! (sub1 n)))]))

The first function computes the term; the second computes the factorial of a natural number. To compute the value of tex2html_wrap_inline72410 , we now just need to ask for (series 10 e-taylor), assuming we want the first 10 items of the sequence included.

Putting everything together, we can define a function that computes the xth power of e. Since the function requires two auxiliaries, we use a local:

(define (e-power x)
  (local ((define (e-taylor i) 
            (/ (expt x i) (! i))) 
          (define (! n) 
            (cond 
              [(= n 0) 1] 
              [else (* n (! (sub1 n)))]))) 
    (series 10 e-taylor))) 


Exercises

Exercise 23.3.6

Replace 10 by 3 in the definition of e-power and evaluate (e-power 1) by hand. Show only those lines that contain new applications of e-taylor to a number.

The results of e-power are fractions with large numerators and denominators. In contrast, Scheme's built-in exp function produces an inexact number. We can turn exact fractions into inexact numbers with the following function:

;; exact->inexact : number [exact] -> number [inexact] 
Test the function and add it to e-power's body. Then compare the results of exp and e-power. Increase the number of items in the series until the difference between the results is small. Solution

Exercise 23.3.7

Develop the function ln, which computes the Taylor series for the natural logarithm. The mathematical definition of the series is

displaymath72422

This Taylor series has a value for all x that are greater than 0.

DrScheme also provides log, a primitive for computing the natural logarithm. Compare the results for ln and log. Then use exact->inexact (see exercise [cross-reference]) to get results that are easier to compare. Solution

Exercise 23.3.8

Develop the function my-sin, which computes the Taylor series for sin, one of the trigonometric functions. The Taylor series is defined as follows:

displaymath72424

It is defined for all x.

Hint: The sign of a term is positive if the index is even and negative otherwise. Mathematicians compute tex2html_wrap_inline72426 to determine the sign; programmers can use cond instead. Solution

Exercise 23.3.9

Mathematicians have used series to determine the value of tex2html_wrap_inline71499 for many centuries. Here is the first such sequence, discovered by Gregory (1638-1675):

displaymath72430

Define the function greg, which maps a natural number to the corresponding term in this sequence. Then use series to determine approximations of the value of tex2html_wrap_inline71499 .

Note on tex2html_wrap_inline71499 : The approximation improves as we increase the number of items in the series. Unfortunately, it is not practical to compute tex2html_wrap_inline71499 with this definition. Solution



[previous] [up] [next]     [index]
Next: The Area Under a Up: Geometric Sequences and Series Previous: Geometric Sequences and Series

PLT