1. Engineering
  2. Computer Science
  3. problem 3 35 points for this problem we will write...

Question: problem 3 35 points for this problem we will write...

Question details

Problem 3. (35 points) For this problem we will write two approximation functions and we will evaluate their error (how close they come to the correct value). Write all code in a file called p3.c sin(x)x-X G Write a function a) An approximation formula for sin(x) when x is small (close to 0) is called sin appr that takes a double x as argument and that returns the approximated value of sin(x) using this formula. Notice that x is expressed in radians. Write the function interface comment, with preconditions and postconditions. b) The factorial of a natural number n is n3.. n n-1n Stirlings approximation formula for .-ervan , n! when n is large (and positive) is e input an integer n and returns the int value of Stirlings approximation for n. Use local variables to store Write a C function called fact appr that takes as intermediary expressions e and 2n, Write the function interface comment, with preconditions and postconditions. c) Write a function called display_ error that takes as input an approximated value and the correct value and that computes the approximation error (the difference between the correct and the approximation) and then displays both values and the error to the terminal. For instance, one could use the display_error function like this double sin c sin (theta) the correct value double sin_a-sin_appr(theta); display_error(sin_a, sin c); To illustrate what the function does, suppose in the code above that sin_c 0.15 and sin_a 0.13. Then, the function computes the error (0.15-0.13 0.02) and displays this to the terminal The correct value is 0.15 and the appraximation is 0.13. The approximation error is 0.02. d) Write the main program that uses the functions written in parts a)-c). The main function should read a double value theta from the terminal, compute the approximation value for sin(theta), the correct value for sin(theta), then use the display_error function, as shown in part c). After that, the program should initialize an int variable n with 10, compute the approximation for n! using the function from part b), compute the correct value for 10! (1 2... 10) and, finally, use the display_error function to display the error for Stirlings factorial approximation.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution