View Single Post
Old 10-27-2005, 09:28 AM   #4 (permalink)
teknomage1
Jack of all trades
 
teknomage1's Avatar
 
Join Date: Feb 2005
Location: Los Angeles
Posts: 598
teknomage1 is on a distinguished road
Send a message via AIM to teknomage1
Okay... Sin doesn't seem any trickier than Cosine but here goes,
Code:
//Equation for Sin(x) 
//Sigma(0, infinity) { -1^n * (x^(2n+1))/(2n+1)! }  - Makes me wish vBulletin supported TeX

//Best to do things properly or not at all
int factorial (int n) {
     int i;
     int result = 1;
     if( n > 0 ) {
	  for( i = 1; i <= n; i++ ) {
	       result = result * i;
	  }
     }

     return result;
}

int taylor_sin (int pos, int x) {
     int i;
     int term;
     int sum = 0;
     
     for( i = 0; i < pos; i++ ) {
	  term = pow(-1, i) * pow(x,(2 * i + 1)) / factorial(2 * i + 1);
	  sum = sum + term;
     }
}
__________________
Stop intellectual property from infringing on me
teknomage1 is offline   Reply With Quote