The calculation of the important mathematical constant e


C Program Assignment:

Write an algorithm and program to compute and compute the square root (√). The calculation of the important mathematical constant e and the square root (√) will be done as the sum of an infinite series:

∞                ∞       

e = ∑ 1/n!      &   √S = ∑ xn+1 = 1/2(xn + S/xn)

n=0               n=0

where x0 is the initial "guess"

See https://en.wikipedia.org/wiki/E_(mathematical_constant) and 

https://en.wikipedia.org/wiki/Methods_of_computing_square_roots for details. Use only the Babylonian method for the square root (√).

Output: Output will include your computed value for e, the library expected value for e, the number of terms (iterations) it took to reach fifteen decimal-place accuracy, and the time (in nanoseconds) that it takes to compute the constant. Output will also include your computed value for the square root of a value input by the user, the expected value using sqrt(), the number of terms (iterations) it took to reach fifteen decimal-place accuracy, and the time (in nanoseconds) that it takes to compute the square root.

Each set of results above should be displayed so as to allow easy comparison of the computed and expected values. Labels should be included, where appropriate.

Input: Accept user input for the value for which the square root is sought. This number will be a real value, and for this assignment will be limited to a real value >= zero. Prompting and validation of the input is, of course, required.

Requirements:

Efficiency should always be considered. Alway choose the most appropriate loop/decision structures and variable/constant types. Functions should focus on a single task. Main() should be high-level tasks only.

The library should be used - see either text index or [K/R] pages 255-256 (Appendix B10) for more details. You may NOT use the math library functions sqrt() or exp() in your computations - directly or indirectly. Instead, use only the delta (difference) of your running computation to determine when to stop. No rounding is permitted.

Program must include (minimum) one function for each computation, in addition to the main program. Other functions developed (likely), as required. Test your program completely.

Solution Preview :

Prepared by a verified Expert
Business Economics: The calculation of the important mathematical constant e
Reference No:- TGS02464505

Now Priced at $30 (50% Discount)

Recommended (93%)

Rated (4.5/5)