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

Need number 12! The power series. Converges to ex for all values for x. Write a

ID: 3533730 • Letter: N

Question

Need number 12!

The power series. Converges to ex for all values for x. Write a function subprogram that uses this series to calculate values for ex to five-decimal-place accuracy (i. e., using terms up to the first one that is less than 10-5 in absolute value) and that uses a function subprogram to calculate factorials. Use these subprograms in a main program to calculate and print a table of values for the function and also the corresponding values of the library function COSH for x = -1 to 1 in increments of 0.1. A more efficient procedure for evaluating the power series in Problem 12 is to observe that if an are two consecutive terms of the series, then. Write a function subprogram to calculate ex using the power series of Problem 12 and using this relationship between consecutive terms. Then use this in a main program to print a table of values for the function.

Explanation / Answer

Final revised code:


#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;

for(x=-1;x<=1;x+=0.1)

{
sum = (exponential(x)+ exponential(-x))/2;
printf("%f %f ",x, sum);

sum=0;
}
return 0;
}


double exponential(double x)
{
double e,sum=1;
int n;

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

n++;
}

return sum;
}

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

return factorial;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote