Sine (Sin) Algorithm Help
So I'm a college student down in Texas and I'm crunching for time atm with finals coming up and programs due in a few days.
Anyways, my professor gave me this:
double sin( float value angle){
Compute the sine of angle using as many terms in the series as required till two successive approximations differ by no more than 0.00000001. Hint: see the example for computing square roots. The sine of a number may be found using the following series.
Sin( x ) = x x3/3! + x5/5! x7/7! + ●●●
}
To figure out the sin function for my program I need to figure out the algorithm to calc a sin.
We were also given this snipet of code to help us try to do this, but it is wiht square roots and is very little help to me if I can't figure out how to put the Sin(x)... into algorithm format.
Here is the code snipet.
/
Code:
/ #define EPSILON 0.000001 // Traditional constant definition.
const double EPSILON = 0.000001;
double sqrt( double n) {
double guess;
if (n >= 0.0) { //verify legal input
for (guess = n;
!( fabs(guess * guess n) < EPSILON);
guess = ( ( n + guess * guess) / (2.0 * guess) )
) /* null body for loop */ ;
return(guess);
}
else
return (-1.0); //error flag
}
Thanks a lot, and if you need anymore details on this, I'd be glad to try to explain better.