Question: Write a C++ Taylor Series sine function: double mySine(const double &, int, double &); - This function takes 3 arguments and returns a type double

Write a C++ Taylor Series sine function:

double mySine(const double &, int, double &); - This function takes 3 arguments and returns a type double value. The return value and arguments are: o [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 o double &result i th 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(/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 [= (/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 o 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) <= tolerance;

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!