Question: Please use C Language and include comment on the code Problem #1 - Taylor Series Convergence (C Program) For this program, let's calculate the Taylor
Please use C Language and include comment on the code




Problem #1 - Taylor Series Convergence (C Program) For this program, let's calculate the Taylor series expansion for the exponential function: e*. The equation we will implement is: 00 1 x X X3 X4 1 T 21 + + +... +4 +... i=0 This summation will converge to e' after some number of terms have been added to the whole. The number of terms will vary depending on the value of x. Note that every term in the summation is positive, so the summation will converge to the actual value from below. "x" is assumed to be > 0. In general, if we wish to test two floating point numbers for equality, we can calculate the absolute value of the difference between the numbers and then determine if that difference is less than some epsilon value. Let's apply that technique to this problem. We'll test the growing sum against the standard et value (as calculated by the exp (x) function) until the difference between the two becomes less than some epsilon (to be defined shortly). At that point we'll consider that the series has converged on the correct value. In addition, we'll track the number of terms that must be added to the sum to achieve convergence and report that value to the user. Functions Your program should contain at least two functions: main() a) standard main function unsigned int factorial (int n) a) This function will calculate n! and return the result as an unsigned int. Since we know that all factorials in this problem are positive, there is no need to return a signed value. Note that the function is to have a return data type of unsigned int. This is a requirement for both Windows and Mac systems. Calculating the factorial of a single number as an unsigned int is the only task for this function. It should not be used to print or perform any other task. If you want to use other functions as well, say, for example, the entire series is calculated in a separate function, that would be okay. Functionality Your program should do the following: Ask the user to enter an "x" value. This value should be a double that is >0. Have the program calculate ex by using the Taylor Series given above and print the following table: For x = 0.3: # Iter e^x Sum Diff - - - - - - - - von WNPIH 1.349859 1.349859 1.349859 1.349859 1.349859 1.349859 1.349859 1.000000 1.300000 1.345000 1.349500 1.349838 1.349858 1.349859 0.34985881 0.04985881 0.00485881 0.00035881 0.00002131 0.00000106 0.00000005 The number of iterations required for convergence is: 7 For x = 0.8: Sum Diff # Iter --- e^x -------- 2.225541 2.225541 2.225541 2.225541 2.225541 2.225541 2.225541 2.225541 1.000000 1.800000 2.120000 2.205333 2.222400 2.225131 2.225495 2.225536 1.22554093 0.42554093 0.10554093 0.02020760 0.00314093 0.00041026 0.00004617 0.00000456 CS1325 - Introduction to Programming page: 3 2.225541 2.225541 2.225541 2.225541 0.00000040 0.00000003 10 The number of iterations required for convergence is: 10 These are actual data and not dummy data. The "# Iter" is the current iteration in the growing sum in the series. The "e^x column is the value of exp (x). The Sum" column is the value of the summation during that particular iteration. And the Dift" column is the difference between ex and Sum. (When this quantity become less than FLT_EPSILON (see below), the iterations should stop.) We can use the built-in epsilon value that is included in
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
