Question: BELOW IS A PROBLEM STATEMENT THAT I CANNOT FIGURE OUT. IT HAS TO BE IN C PROGRAM NOT C++. I ALSO TYPED THE PROFESSORS EXAMPLE
BELOW IS A PROBLEM STATEMENT THAT I CANNOT FIGURE OUT. IT HAS TO BE IN C PROGRAM NOT C++. I ALSO TYPED THE PROFESSORS EXAMPLE BELOW FOR REFERENCE, BUT HOWEVER, WE ARE REQUIRED TO COME UP WITH OUR OWN CODE THAT HAS THE SAME OUTCOME.
Problem Statement: Develop a C Program for Exponential Value Determination using Numerical Approximation for e as given by the Taylor series expansion; This series approximation for e is given by the series written below:
e = 1 + 1 + 1/2! + 1/3! + 1/4! + 1/5! + 1/6! .... we stop at 6! division in this program.
Hence, compute the relative error and absolute error after computing the true value of e using the math function exp().
(PROFESSORS )C-Program example:
/* Exponential Value Approximation ('e' value in Math Computations) */
/* Approximation for 'e' is given by the series written below: */
/* e = 1 + 1 + 1/2! + 1/3! + 1/4! + 1/5! + 1/6! .... we stop at 6! division in this program */
/* Hence compute the relative and absolute error */
#include
#include
#include
int main()
{
printf(" The computed approximation for exponential 'e': (using 7 terms of series)");
printf(" The series for e = 1 + 1 + 1/2! + 1/3! + 1/4! + 1/5! + 1/6!");
double eapprox=2; /* intialize eapprox value as 2*/
double etruevalue = exp(1.0);
int n; /* term number in the approx series */
double sum = 0; /* assign sum variable to zero */
printf(" The eapprox value = %lf for n=1, first two terms",eapprox);
/* add each term in the series and add each term to eapprox value */
n=2; /* do the sum for n =2, third term 1/2! term */
sum = sum + 1.0/n;
eapprox = eapprox + sum;
printf(" The eapprox value = %lf for n=2, for three terms",eapprox);
/* do the sum for n =3, fourth term 1/3! term */
n++; /* this is the same as n = n+1, shortened as n++, now n = 3 */
sum = sum*(1.0/n);
eapprox = eapprox + sum;
printf(" The eapprox value = %lf for n=3, for four terms",eapprox);
/* do the sum for n =4, fifth term 1/4! term */
n++; /* this is the same as n = n+1, shortened as n++, now n = 4 */
sum = sum*(1.0/n);
eapprox = eapprox + sum;
printf(" The eapprox value = %lf for n=4, for five terms",eapprox);
/* do the sum for n =5, sixth term 1/5! term */
n++; /* this is the same as n = n+1, shortened as n++, n = 5 */
sum = sum*(1.0/n);
eapprox = eapprox + sum;
printf(" The eapprox value = %lf for n=5, for six terms",eapprox);
/* do the sum for n =6, seventh term 1/6! term */
n++; /* this is the same as n = n+1, shortened as n++, n = 6 */
sum = sum*(1.0/n);
eapprox = eapprox + sum;
printf(" The eapprox value = %lf for n=6, for seven terms",eapprox);
/* Print e true value */
printf(" The e true value (math function computed) is = %lf ",etruevalue);
/* Print rel error and abs error on computing e approx value*/
double relerror=0, abserror=0;
abserror = etruevalue - eapprox;
relerror = abserror/etruevalue*100;
printf(" The absolute error on computing approx e = %lf", abserror);
printf(" The relative error in percent on computing approx e = %lf ", relerror);
return 0;
}
Output of this Program:
The computed approximation for exponential 'e': (using 7 terms of series)
The series for e = 1 + 1 + 1/2! + 1/3! + 1/4! + 1/5! + 1/6!
The eapprox value = 2.000000 for n=1, first two terms
The eapprox value = 2.500000 for n=2, for three terms
The eapprox value = 2.666667 for n=3, for four terms
The eapprox value = 2.708333 for n=4, for five terms
The eapprox value = 2.716667 for n=5, for six terms
The eapprox value = 2.718056 for n=6, for seven terms
The e true value (math function computed) is = 2.718282
The absolute error on computing approx e = 0.000226
The relative error in percent on computing approx e = 0.008324
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
