Question: Purpose: Experience using arrays and numeric functions. Create and debug a program with greater complexity. Assignment: Write a program that demonstrates the correct operation of

Purpose: Experience using arrays and numeric functions.

Create and debug a program with greater complexity.

Assignment: Write a program that demonstrates the correct operation of the described sin_() function. float sin_ (float input_angle)

The calculation of this trigonometric value will be performed in a multi-stage process; first a look up table (array) will be built storing the sin() for all values between 0 degrees and 359 degrees using a taylor series. (see https://en.wikipedia.org/wiki/Taylor_series for background and the algorithm to be used).

This lookup table is created once and then used when the function is called for the life of the program.

The sin_() function will use the lookup table to linearly interpolate between two values of the lookup table to return the answer. (see https://en.wikipedia.org/wiki/Linear_interpolation for background and the equation to be used for linear interpolation).

The advantage to this design is the function call is very fast, requiring only some addition and division. Slower calculations, like the calculation of the sin in the lookup table is done only one time during initialization.

An example of using a look up table and interpolation: To solve for X = 7 Y = (25(10-7) +100(7-5) ) / (10-5) Y = (75 +200) / 5 Y = 55 In this example, the function we are interpolating is Y=X*X. An X value of 7 would give 49, so the Error in using the lookup table and interpolation is: Error = Correct Measured Error = 49 55 = -6 You will find the sin() function calculated as described above with be much closer to actual value. Specific Requirements for the sin_() function: The input angle is provided to the function in degrees.

Input values must be >= 0.0 and < 360.0 . Values outside of this range return a 0.0 A function named init(), with no parameters, will be called as the first line of the main program. This function will build the look up table as described.

Use a Taylor Series with 4 terms to calculate the sin value stored in the look up table. Calculate the factorial using an iterative (non-recursive) function. Specific Requirements for the program: A function named init(), with no parameters, will be called as the first line of the main program. This function will build the look up table as described. It is acceptable for the look up table to be a global variable. The program will read from stdin.

The input shall be a single floating point number on a line. Input numbers out of range will be ignored. Input of text or other garbage will be ignored. The program shall continue to read input and calculate a result until a -1 is entered. A -1 will cause the program to exit For each number entered, with the exception of a -1, the program will print 4 numbers; the input value, the value returned from sin_, the value returned from sin(), and the difference between sin() and sin_() {the Error}.

When you test the program, create a data file with input values, one per line, with a -1 being the last number in the file. Use bash input redirection ( <) to execute the program with this input file. Each output number will be separated by a space. Headers to be used are stdio.h, assert.h, and math.h For numerical constants (like PI), use the constants already defined in math.h Every function must have comments that describe its purpose,implementation, and interface. Any pre and post conditions for a function must be described in the comments, and checked at runtime using assert ().

The program will be contained in a single C file. The file shall be named hw02_last_name_first_name.c . Use the option -std=c99 when you compile this code. You will turn into blackboard a single C file. Grading Criteria: Program compiles without warnings. ( -Wall ) Output values are correct. This will be verified by a set of test values created by the grader. The output as described above should be easily consumed by gnuplot for a graphical evaluation of the program outputs Compliance with assignment requirements. How to create a lookup table using a Taylor series

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!