[an error occurred while processing this directive]

CMSC201
Programming
Project Two

Taylor series

out Wednesday 9/25/96
due Wednesday 10/09/96
    at Midnight


Brook Taylor

Introduction

How can we calculate values for common functions like the trigonometric functions sine and cosine? In the early 1700's mathematicians such as Brook Taylor developed techniques in which the value of a function like sin(x) could be expressed as the sum of an infinte series of smaller and smaller terms. This provided a useful way of approximating the value of such functions by calculating the sum of an initial number of these terms. The more terms that were used in the calculation, the better the approximation.

Any function f(x) can be expressed as a polynomial in x (which is an "infinite series") using a popular method called the Taylor expansion. This is an important technique and the knowledge of it has saved the life of at least one famous scientist, as the newspaper item "Taylor Series - a matter of life or death" attests.

Taylor's Series for any function f(x) expanded around a point x=a can be expressed as:

where: You should note that the f(x) expansion in (1) is an infinite series, the nth term of the series is: (x-a)n*fn(a)/n!, where fn(a) is the nth derivative of f(x) evaluated at x=a.

Each successive term in the infinite series gets smaller and smaller. We can use this method to compute an approximate value of a function at a point x by calculating a certain number of terms, say the first ten, and summing them. The more terms we add up, the more accurate our approximation.

The task

For your second project assignment, write a program that uses the first five terms of a Taylor series expansion to compute values of the trigonometric functions sine and cosine at a given point. Since all these functions sin(x), cos(x) and their derivatives are defined at 0, we can choose a=0 in the Taylor's series. Using (1), the first five terms of the Taylor series expansion for these two functions expanded around x = 0 are: Your program should begin by asking the use to specify a whether he wants to compute the sine or cosine function and the point as a floating point number (in radians) at which it should be evaluated. Here is a sample output session in which the user's input is shown in italics.

Notes

What to hand in

Use the submit program to submit a copy of your source code. We will not look kindly on people who are unable to successfully use submit for this second assignment. [an error occurred while processing this directive]