Hello,

So I made sin, cos, and tan functions in main based on the initial radian angle of 45 radians.

I converted radians into degrees, by dividing the angle by 180 and then multiplying by pi later on.

I then sent this value to their appropriate functions, which take in this angle, and approximate a sin, cos, or tan value given the correct use of the Taylor series for each function.

The thing is, it works in radians, and just checked via my Texas instruments calculator (aka a TI-30), and the sin, cos, and tan values are approximately okay in radians, NOT DEGREES.

I'm pretty sure that in order to go from radians to degrees, you have to divide by 180, and multiply by pi, so I don't understand how this is still giving me a radian value...

All that I could think of are two possiblities:

1. I didn't convert to degrees correctly

or

2. The Taylor series maybe uses radians, or maybe I didn't write the functions correctly.

Here's my code:

Code:#include <iostream> #include <cmath> // This library is used for the sin, tan, and cos functions later using std::cout; using std::endl; /* 3. The trigonometry functions (sin(), cos(), and tan()) in the standard <cmath> library take arguments in radians. Write three equivalent functions, called sind(), cosd(), and tand(), which take arguments in degrees. All arguments and return values should be type double. */ // Function Prototype for Sin function: double sind(double sin_degree_arg); // Function Prototype for Cos function: double cosd(double cos_degree_arg); // Function Prototype for Tan function: double tand(double tan_degree_arg); int main() { // Instead of making the functions on their own, start making // them in main and get them working FIRST double sin_radian_arg; double sin_degree_arg; double cos_radian_arg; double cos_degree_arg; double tan_radian_arg; double tan_degree_arg; double pi; sin_radian_arg = 45; cos_radian_arg = 45; tan_radian_arg = 45; pi = 3.14159265; // Goals for Sin function: // Find out how to convert a radian argument into degrees to use for // the sin function: // We're basically converting degree values in radians into degrees // sin of angle = len of opp side / hyp // Multiply the angle by pi, and divide by 180 (remember the Unit Circle? :D) // Always assume hypotenuse is 1 // http://www.mathsisfun.com/sine-cosine-tangent.html // http://www.homeschoolmath.net/teaching/sine_calculator.php sin_degree_arg = sin_radian_arg / 180; sin_degree_arg*= pi; cout << "Original radian_arg value = " << sin_radian_arg << endl; cout << "Degree_arg value = " << sin_degree_arg << endl; sind(sin_degree_arg); // Okay, so basically a calculator will take in a radian amount, convert it // to degrees by multiplying the number by 180, and THEN dividing it by pi // So divide the degree amount by pi: // Model equation is as follows, basically its a Taylor Series from Calc 2: // sinx = x - ((x^3)/3) + ((x^5) / 5) - ((x^7) / 7) // Use pow() from cmath: pow(number, exponent) // sin_value = degree_arg - (pow(degree_arg, 3))/(3*2*1) + (pow(degree_arg,5))/(5*4*3*2*1) - (pow(degree_arg,7))/(7*6*5*4*3*2*1); // Cos: // Taylor series for cosx = 1 - x^2 / 2! + x^4 / 4! cos_degree_arg = cos_radian_arg / 180; cos_degree_arg *= pi; cosd(cos_degree_arg); // Tan: // Taylor Series for tan: tan x = x + x^3/3 + 2*x^5/15 + 17*x^7/315 tan_degree_arg = tan_radian_arg / 180; tan_degree_arg *= pi; tand(tan_degree_arg); return 0; } double sind(double sin_degree_arg) { double sin_value; cout << "Sin Degree Arg received = " << sin_degree_arg << endl; sin_value = sin_degree_arg - (pow(sin_degree_arg, 3))/(3*2*1) + (pow(sin_degree_arg,5))/(5*4*3*2*1) - (pow(sin_degree_arg,7))/(7*6*5*4*3*2*1) + (pow(sin_degree_arg, 9))/(9*8*7*6*5*4*3*2*1); cout << "Sin value = " << sin_value << endl; return sin_value; } double cosd(double cos_degree_arg) { double cos_value; cout << "Cos Degree Arg Received = " << cos_degree_arg << endl; cos_value = 1 - (pow(cos_degree_arg, 2))/(2*1) + (pow(cos_degree_arg, 4))/(4*3*2*1) - (pow(cos_degree_arg, 6))/(6*5*4*3*2*1) + (pow(cos_degree_arg, 8))/(8*7*6*5*4*3*2*1); cout << "cos_value = " << cos_value << endl; return cos_value; } double tand(double tan_degree_arg) { double tan_value; cout << "Tan Degree Arg Received = " << tan_degree_arg << endl; // Value is NOT correct --> check math, its probably a matter of // using parenthesis incorrectly tan_value = tan_degree_arg + pow(tan_degree_arg,3)/3 + 2*pow(tan_degree_arg,5)/15 + 17*pow(tan_degree_arg,7)/315; cout << "tan_value = " << tan_value << endl; return tan_value; }

Tweet This+ 1 thisPost To Linkedin