polynomial of degree n as follows: 1 Here is a sample run: x = 0.900000 n = 5 2 1 2 x + 4 In(1+x)≈x- +…+(−1)n+Dr” n This is called a power series approximation. Write a program 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. + 1 approximate value = 0.692073 actual value = 0.641854 relative error = 7.824064 percent For marking purposes use r = 0.9 and n = 40. 5

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Plz solve the question using c programming without using the library # include stdlib.h. or string.h .. Only use # include stdio.h and # include math.h And printf, scanf, fout, fin.
4. In your Calculus course you will learn that the function ln(1 + x) can be approximated by a
polynomial of degree n as follows:
1
≈x-x+
2
Here is a sample run:
x = 0.900000
n=5
2
1
3
3
approximate value = 0.692073
actual value = 0.641854
relative error = 7.824064 percent
1
pea
4
In(1+x)=x-
This is called a power series approximation.
Write a program 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.
... + (−1)(¹+¹)x” /n
Transcribed Image Text:4. In your Calculus course you will learn that the function ln(1 + x) can be approximated by a polynomial of degree n as follows: 1 ≈x-x+ 2 Here is a sample run: x = 0.900000 n=5 2 1 3 3 approximate value = 0.692073 actual value = 0.641854 relative error = 7.824064 percent 1 pea 4 In(1+x)=x- This is called a power series approximation. Write a program 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. ... + (−1)(¹+¹)x” /n
Expert Solution
Step 1

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

int main()
{
   float x,sum=0,dev;
   int n,i;
   FILE *fp=fopen("powerseriesout.txt","w");
   printf("Enter Value for x");
   scanf("%f",&x);
   printf("Enter The Degree for x");
   scanf("%d",&n);
   for(i=1;i<n+1;i++)
   {
       sum+=((pow(-1,i+1)*pow(x,i))/i);
   }
   fprintf(fp,"x =%f\n",x);
   fprintf(fp,"n =%d\n",n);
   fprintf(fp,"Approximate Value =%f\n",sum);
   fprintf(fp,"Actual Value =%f\n",log(1+x));
   dev=sum-log(1+x);
   dev/=log(1+x);
   dev*=100;
   fprintf(fp,"Relative Error =%f percent",dev);
}

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education