Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Taylor Series: Trigonometric Functions Topics covered: Loops, Mathematical Library Functions, and Functions Lab Due Feb 5 at midnight Objective: This lab is an introduction to

Taylor Series: Trigonometric Functions

Topics covered: Loops, Mathematical Library Functions, and Functions

Lab Due Feb 5 at midnight

Objective:

This lab is an introduction to functions. It utilizes the concepts of loop structures, logical and relational operators, C++ library functions, and C++ mathematical operators.

Please read this over carefully before beginning to work on this laboratory. It is strongly suggested that you create a script (possibly pseudo code or even a flowchart) for solving this problem. This project is best solved by breaking it into small easily solved problems.

Checklist:

Read over and understand thespecificationsection of this document.

Create a folder for this assignment under your Assignments Hierarchy.

Create and test degreesToRadians(x) function indegreesToRadians.cpp

Create and test factorial(n) function infactorial.cpp

Create a new source code file calledtaylorSeries.cpp

Copy factorial and degreesToRadians functions from previous steps intotaylorSeries.cpp.

Create all function prototypes including factorial and degreesToRadians and place them above int main().

Implement the Taylor Series for mySine(x) function.

Implement the Taylor Series for myCosine(x) function.

Create myCosecant(x)in terms of mySine(x) function above

Create mySecant(x)in terms of myCosine(x) function above

Create myTangent(x) and myCotangent(x) in terms of mySine(x) and myCosine(x)

Display a table of results. See example output.

Submit all three .cpp files created in this laboratory to Mimir

Specification:

Using a loop go from 0 to 360 degrees in steps of 15-degrees and produce a table of Math Library Sine function, Math Library Cosine function, Taylor Series Sine function, Taylor Series Cosine function, Tangent (based on Taylor Series), Cotangent (based on Taylor Series), Cosecant (based on Taylor Series) and Secant (based on Taylor Series) function.

Calculate the Cosine and Sine of this angle using the Taylor Series given below:

Sine(x) = x x3/3! + x5/5! x7/7! + x9/9! x11/11! +

Cosine(x) = 1 x2/2! + x4/4! x6/6! + x8/8! x10/10! +

The variable x is in radians and not degrees.

Note: See the PI calculator example in the examples directory on blackboard to get you started with series calculations.

Other trigonometric functions can be calculated using:

Tangent(x) = Sine(x)/Cosine(x)

Cotangent(x) = Cosine(x)/Sine(x)

Secant(x) = 1.0/Cosine(x)

Cosecant(x) = 1.0/Sine(x)

You should use awhileloop for this series. You will terminate the loop when the difference between previous and current calculated values is equal to or less than 0.00001.

To convert from degrees to radians use:

angle_in_radians = angle_in_degrees * PI/180.0;

You should implement the above conversion as a function called to degreesToRadians(x).

To calculate the factorial of a number use a function called factorial(x).This function should take a double as a parameter and return a double as value. The factorial should be calculated using a forloop. Do not use one of the manyrecursiveversions of this function available from the internet.

Note: All function variables and functions return types should bedoubles.

Finally, display the values using a in a properly formatted table in landscape format. Each value should show at least 4 digits after the decimal point. The table should print the values in order given above.

Task 1:

Create a new source file calleddegreesToRadians.cppto create and test function called degreesToRadians(x). Compile using standard command line. Please use the following function prototype:

double degreesToRadians(double angle_in_radians);

Note: For PI add the following above int main(){

const double PI = atan(1.0)*4.0;

The degreesToRadians function will take double as a parameter and return a double as a value.

You should verify with hand calculations and cin/cout statements in main() that your function is producing the correct results for sample test values in the range of 0 to 2Pi (0 to 360 degrees). Please include these results in the comments section of your .cpp source file.

See sample output below to determine if your program is working properly.

Sample Output:

./degreesToRadians

Degrees to Radians Test Driver

Enter angle in degrees: 45

Angle in Radians: 0.7854

./degreesToRadians

Degrees to Radians Test Driver

Enter angle in degrees: 90

Angle in Radians: 1.5708

./degreesToRadians

Degrees to Radians Test Driver

Enter angle in degrees: 270

Angle in Radians: 4.7124

Task 2:

Create a new source file calledfactorial.cppto create and test factorial(x) function. Compile it using the standard command line.

You should verify with hand calculations and cin/cout statements in main() that your function is producing the correct results for test input values in the range of 0 to 10. See sample output for details.

The factorial function will take double as a parameter and return a double value which corresponds to the following prototype:

double factorial(double factorial);

Note: You must use a for loop to implement this function. Please do not copy one of the many recursive functions from Google.

Sample Output

./factorial

Factorial Test Driver

Enter N: 7

Factorial: 5040

./factorial

Factorial Test Driver

Enter N: 10

Factorial: 3628800

./factorial

Factorial Test Driver

Enter N: 13

Factorial: 6227020800

Task 3:

Create a new source file calledtaylorSeries.cppso you can create and test a Taylor Series version of the Sine(x) function. Call your function mySine(x) which takes a double as a parameter and returns a double as a result.

You will need to copy the functions fromTask 1andTask 2to this new source file. You should compare the result to the system sin(x) function from the math library for values of 0 to 360 (0 to 2PI). They should be within the error (0.0001) indicated above.

Note: Make sure to create a function prototype for mySine() and place it above main()

Task 4:

Update the file calledtaylorSeries.cppso you can create and test a Taylor Series version of theCosine(x)function.

This function should by calledmyCosine(x)and take one double as a parameter and return a double as a result. You should compare the result to the systemcosfunction from the math library for values of 0 to 360 (0 to 2PI). They should be within the error (0.0001) indicated above.

Note: Make sure to create a function prototype for myCosine() and place it above main()

Task 5:

Using the same source file add your remaining trigonometric function in terms of yourmyCosine(x)andmySine(x)function in Task 3 and 4 above. All these functions should take a double as a parameter and return a double as the result.

Note: Make sure to create a function prototypes for all functions involved and place them above main()

Task 6

Finally, create a table from 0 to 360 degrees in steps of 15 containing the following:

Angle in degrees

Angle in radians

Your Trigonometric functions

The C++ Math library values forsinandcos.These should be grouped together with themySineandmyCosinecreated above.

Please see the sample output below for output formatting details.

Sample Output:

System System System

Degrees Radians Sin Sin Cos Cos Tan Tan CoTan SecantCoSecant

0 0.0000 0.0000 0.0000 1.0000 1.0000 0.0000 0.0000 inf 1.0000 inf

15 0.2618 0.2588 0.2588 0.9659 0.9659 0.2679 0.2679 3.7321 1.0353 3.8637

30 0.5236 0.5000 0.5000 0.8660 0.8660 0.5774 0.5774 1.7321 1.1547 2.0000

45 0.7854 0.7071 0.7071 0.7071 0.7071 1.0000 1.0000 1.0000 1.4142 1.4142

60 1.0472 0.8660 0.8660 0.5000 0.5000 1.7321 1.7321 0.5774 2.0000 1.1547

75 1.3090 0.9659 0.9659 0.2588 0.2588 3.7321 3.7321 0.2679 3.8637 1.0353

90 1.5708 1.0000 1.0000 0.0000 0.0000 inf inf 0.0000 inf 1.0000

105 1.8326 0.9659 0.9659 -0.2588 -0.2588 -3.7321 -3.7321 -0.2679 -3.8637 1.0353

120 2.0944 0.8660 0.8660 -0.5000 -0.5000 -1.7321 -1.7321 -0.5774 -2.0000 1.1547

135 2.3562 0.7071 0.7071 -0.7071 -0.7071 -1.0000 -1.0000 -1.0000 -1.4142 1.4142

150 2.6180 0.5000 0.5000 -0.8660 -0.8660 -0.5774 -0.5774 -1.7321 -1.1547 2.0000

165 2.8798 0.2588 0.2588 -0.9659 -0.9659 -0.2679 -0.2679 -3.7321 -1.0353 3.8637

180 3.1416 0.0000 0.0000 -1.0000 -1.0000 -0.0000 -0.0000 -inf -1.0000 inf

195 3.4034 -0.2588 -0.2588 -0.9659 -0.9659 0.2679 0.2679 3.7321 -1.0353 -3.8637

210 3.6652 -0.5000 -0.5000 -0.8660 -0.8660 0.5774 0.5774 1.7321 -1.1547 -2.0000

225 3.9270 -0.7071 -0.7071 -0.7071 -0.7071 1.0000 1.0000 1.0000 -1.4142 -1.4142

240 4.1888 -0.8660 -0.8660 -0.5000 -0.5000 1.7321 1.7321 0.5774 -2.0000 -1.1547

255 4.4506 -0.9659 -0.9659 -0.2588 -0.2588 3.7321 3.7321 0.2679 -3.8637 -1.0353

270 4.7124 -1.0000 -1.0000 -0.0000 -0.0000 inf inf 0.0000 -inf -1.0000

285 4.9742 -0.9659 -0.9659 0.2588 0.2588 -3.7321 -3.7321 -0.2679 3.8637 -1.0353

300 5.2360 -0.8660 -0.8660 0.5000 0.5000 -1.7321 -1.7321 -0.5773 2.0000 -1.1547

315 5.4978 -0.7071 -0.7071 0.7071 0.7071 -1.0000 -1.0000 -1.0000 1.4142 -1.4142

330 5.7596 -0.5000 -0.5000 0.8660 0.8660 -0.5774 -0.5774 -1.7321 1.1547 -2.0000

345 6.0214 -0.2588 -0.2588 0.9659 0.9659 -0.2679 -0.2679 -3.7321 1.0353 -3.8637

360 6.2832 -0.0000 0.0000 1.0000 1.0000 -0.0000 0.0000 inf 1.0000 inf

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions

Question

Focus on your message to help you become a more confident speaker.

Answered: 1 week ago

Question

Consider your own interests and experiences when selecting a topic.

Answered: 1 week ago

Question

Search for topics on the Internet, in the media, and in books.

Answered: 1 week ago