Question: language: c++ please use function prototype provided B. Taylor Series Use filename: Taylor.cpp Background - You should know from your calculus classes that any well-

language: c++

please use function prototype provided

language: c++ please use function prototype provided B. Taylor Series Use filename:

Taylor.cpp Background - You should know from your calculus classes that any

well- behaved function can be represented as an infinite series known as

B. Taylor Series Use filename: Taylor.cpp Background - You should know from your calculus classes that any well- behaved function can be represented as an infinite series known as a Taylor Series (see: 2). The focus of this lab element is to compute trigonometric function values for sin and cos by explicitly using their (truncated) Taylor (actually, McLaurin) Series representations. These are given by sin(x) = x - x3/3! + x5/5! - x?/7!... cos(x) = 1 - x2/2! + x4/4! - x5/6!... Notice that sin(x) has odd exponent values and cos(x) has even exponent values. Later on, in your math classes you will learn about odd and even functions and their properties. sin is an odd function and cos is an even function. When you call a math function in your code, say, for example, log10(), your computer actually gets the result by constructing and evaluating a truncated Taylor Series for the function. This lab element requires the development of several functions. Prototypes and a brief description are given in the following. int factorial (const int &); - use function from Part A double degreesToRadians (const double &); - As the name implies, this function converts the angle value which is input with units of degrees to radians. Recall, radians = degrees (1/180.) double mySine(const double &, int, double &); - This function takes 3 arguments and returns a type double value. The return value and arguments are: [return type double] - the function returns the truncated Taylor Series sum which is the evaluation of sin(x), where x is the first argument (see the following) o const double &x - angle value in radians o int i - position of term in Taylor series that is to be assigned to next argument double &result - ith term (2nd argument) in truncated Taylor Series for sin(x). This term is effectively returned to main() since it is called by reference. For example, the function call: double sineValue = mySine(PI/4., 3, seriesTerm); // 2nd term Loaded into seriesTerm will return the truncated Taylor Series evaluation for sin(1/4) and assign it to the variable double sineValue. The third argument, seriesTerm is passed to mySine by reference. In the body of the function, the 3rd term (2nd argument = 3) in the Taylor series expansion [= (1/4)5/5!] is assigned to this argument. Since it is passed by reference, the value of this term is available in your main() function in the variable, seriesTerm This function sets up a loop to sum up the individual terms in the Taylor Series. You will need to track the series sum using two variables in your mySine function: double sum_old = 0., sum_new = (appropriate initial value here); The variables sum_old and sum_new must be continually updated as each new term is added to the Taylor Series o The Taylor Series is truncated (or stopped) when adding the next term to series results in a change to the series sum that is less than the specified tolerance value (=10-6). More explicitly, the Taylor Series is truncated when fabs(sum_new - sum_old)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!