# help on c programming involving taylor series

• 05-04-2007
harlow23
help on c programming involving taylor series
Create a program that will approximate the error function erf(x) and erfc(x). Use the following Taylor series expansion:

http://i49.photobucket.com/albums/f2...r/untitled.jpg

Code:

``` Restrictions: 1. Use at most 6 variables in the main function. 2. Create a separate function for power using recursion. 3. Create a separate function for factorial using iteration. 4. Calculate the approximation until the 100th term of the Taylor series and print out approximation up to 4 decimal places. *I have accomplished numbers 2 and 3. 2.) int power(int b, int e){     if(b==0 && e==0){             printf("Invalid.\n");             main();             }     if(e==1){             return b;             }     if(e==0){             return 1;             }     else{         return b*power(b,e-1);         } } 3.) double factorial(double value){     int ctr;     double fact;     if(fact<0){               printf("Invalid.\n");               main();               }     else{     fact=1;     for(ctr=1;ctr<=value;ctr++){                               fact*=ctr;                               }     return fact;     } } ***Any help will be appreciated. Thanks!```
• 05-04-2007
robatino
You switched 2) and 3). The power function should use a floating-point type for b and its return value. The factorial should use an integer type for its argument and return value.

Edit: Also, you shouldn't call main() explicitly from within the program. It should only be called automatically when the program starts. There's no reason to anyway since you're only calling these functions from within your own program so you have control over the arguments and can ensure that they are valid, so you don't really need to check them.
• 05-04-2007
harlow23
thanks for the response. i understand. but now my problem now is how to program that taylor series expansion. it's infinite..
• 05-04-2007
robatino
As I read the specification, it says to calculate the sum of the first 100 terms of the series, and then print (to 4 decimal places) the resulting number. Seems clear enough. (If you had been asked to determine the number of terms necessary to get a given level of accuracy, that would be significantly harder.)
• 05-04-2007
harlow23
oh yeah, so that would mean n=0 to n=100. basically the user has to enter the value of x.
thanks!