Homework 1-The sine of an angle (specified in radians)
Homework 1 The sine of an angle (specified in radians) can be computed by making use of the approximation sinx≈x if x is sufficiently small, and using the trigonometric identity sinx=3sinx 3−4sin3x 3 to reduce the size of the argument to sin. For purposes of this exercise we will consider the angle to be small if it is less than or equal to 0.1 radians. Here is the C++ code that uses recursion and the formulas above to calculate the sine of any angle: #include <cmath #include “mytrig.h” using namespace std; static double utility(double y) { return 3.*y - 4.*y*y*y; } double mysin(double angle) { if (abs(angle) <= 0.1) return angle; else return utility(mysin(angle/3.)); } We can define cosine and tangent in terms of sine as: cosx=sinx 2 tanx=sinx cosx Create a static library named libmytrig.a that contains the object code for functions mysin(), mycos() and mytan() based on the definitions and code above. The code for each of the mysin, mycos, and mytan routines should be in separate files. Create a header file (named mytrig.h) for the library that contains the function prototypes. Write a test program that prints out the sine, cosine, and tangent calculated using these functions for angles between 0 and 180 degrees in 10 degree increments. (Don't forget to convert from degrees to radians before calling your routines!) The test program should also print out the results calculated using the built-in trigonometric functions for comparison. Submit (by email in a zip archive) all source files, a file containing a print-out of the results from your test program, and another file listing the commands that are used to build the library and the test program. The subject line should be as follows: “CS375 HW 1 Your Name Here”. Notes: 1. The number π is defined as M_PI in the cmath header file. 2. The UNIX script command can be used to copy to a file everything printed to a terminal. It is useful for students who need a hardcopy record of an interactive session. Press ^-D (control-d) to end the script session.