Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using C programming, calculate the Taylor series expansion for the exponential f

ID: 3529147 • Letter: U

Question

using C programming, calculate the Taylor series expansion for the exponential function: e^x your function should contain at least two functions: 1) main () a) standard main function 2) unsigned long factorial (int n) a) this function will calculate n! and returnt he resutl as an unsigned long. the program should do the following: 1) ask the user to enter "x" value. this value should be a double that is >0. 2) have the program calculate e^x by using taylor series given above and print the following table: for x=.3: #iter e^x sum diff 1 1.349859 1.0000000 0.34985881 2 1.349859 1.3000000 0.49858881 3 1.349859 1.3450000 0.00485881 ...... .... ... 7 1.349859 1.349859 0.00000005 the number of iteratsion required for convergence is: 7

Explanation / Answer


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define TRUE 1

double exponential (double);
int factorial (int);

int main (void)
{
double x;
double sum;

printf( "enter value of x: ");
scanf( "%lf", &x);


sum += exponential(x);

printf( "Taylor Series of e^x is approximately = %.6f ", sum);

system("PAUSE");
return 0;
}


double exponential(double x)
{
double e;
int n;

n=1;
while (TRUE)
{
e = pow(x, n) / factorial(n);
if( e < 0.000001)
break;

n++;
}

return e;
}

int factorial (int n)
{
int factorial=1;
while(n > 1)
{
factorial *= n;
n--;
}

return factorial;
}