The exponential function is defined as the follow Taylor series The precise valu
ID: 3680683 • Letter: T
Question
The exponential function is defined as the follow Taylor series The precise value of the limit of the following series as n goes to infinity. We can only approach the limit with write steps (increasing the value of n). Write a C program to compute this exponential function at given point (x) with given number of steps (n). Compare your result with the "near precise' value provided by the math library. You must define recursive function(s) to solve this problem. The following is a sample output that I expect to see.Explanation / Answer
#include <stdio.h>
#include <math.h>
int factorial(int n)
{
if(n == 0)
return 1;
else if (n == 1)
return 1;
else
return n * factorial(n - 1);
}
int main() {
int n;
double x;
printf("Enter x to evaluate Exp(x):");
scanf("%lf",&x);
printf(" Enter number of steps:");
scanf("%d",&n);
double total = 0,temp = 0;
int fact = 1;
double libval = exp(x);
printf(" Your Result Library Result ");
int i;
total = 1;
printf(" step 1: %lf %lf", total, libval);
for(i = 1; i <n; i++) {
temp = pow(x,i);
fact = factorial(i);
total += temp/fact;
printf(" step %d: %lf %lf", (i+1), total, libval);
}
}
-----output----------------------
1
10
Enter x to evaluate Exp(x):
Enter number of steps:
Your Result Library Result
step 1: 1.000000 2.718282
step 2: 2.000000 2.718282
step 3: 2.500000 2.718282
step 4: 2.666667 2.718282
step 5: 2.708333 2.718282
step 6: 2.716667 2.718282
step 7: 2.718056 2.718282
step 8: 2.718254 2.718282
step 9: 2.718279 2.718282
step 10: 2.718282 2.718282
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.