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

Please use the programming language of C, using the compiler of Dev C++ (Not nec

ID: 3588549 • Letter: P

Question

Please use the programming language of C, using the compiler of Dev C++ (Not necessary).

In your Calculus course you will learn that the function ln(1 + x) can be approximated by a
polynomial of degree n as follows:
ln(1 + x) x
1
2
x2 +
1
3
x3
1
4
x4 +
1
5
x5 + · · · + (1)(n+1)xn/n
This is called a power series approximation.
Write a program, powerseries.c, to check the accuracy of this formula. Your program must
prompt the user for the value of x (where |x| < 1) and the degree, n, of the polynomial to use.
Your program should then write the values of x, n, the approximation, the actual value and
the percent relative error to the output file powerseriesout.txt.
For marking purposes use x = 0.9 and n = 40.
Here is a sample input and output:
x = 0.900000
n = 5
approximate value = 0.692073
actual value = 0.641854
relative error = 7.824064 percent

Explanation / Answer

powerseries.c

int main()
{
//int array[MAXSIZE];
int i=2, num, a=12;
float x, polySum;

printf("Enter the degree of the polynomial ");
scanf("%d", &num);
printf("Enter the value of x ");
scanf("%f", &x);
/* Read the coefficients into an array */
polySum = log(1+x);
polySum = polySum *x;
  
//printf("%lf", polySum);
while(i<=num)
{
if(a%2 == 0)
a=a*-1;
polySum+(a*pow(x,i));
a=fabs(a);
i++;
a++;
  
}
printf("the approximate value of given polynom is : %lf",polySum);
return 0;
}