Question: THIS PROGRAM MUST BE COMPLETED IN C: The technique of interpolation can be used for estimating values between data points. The simplest method of interpolation

THIS PROGRAM MUST BE COMPLETED IN C:

The technique of interpolation can be used for estimating values between data points. The simplest method of interpolation is called linear interpolation, shown in the following figure. In this case, two adjacent points are connected with a straight line.

In a linear interpolation, a straight line first-order polynomial is used to connect two adjacent points. For a smoother interpolation, a second or third-order polynomial (or even cubic splines) can be used to interpolate values between every two points. These latter techniques are outside the scope of this assignment. For purposes of this assignment, lets initialize our data set to contain the following points. (Later we may modify this program to read data points from an input file.)

You can store the time and distance values in two separate parallel arrays or in an array of structures. Your program should do the following:

1. Initialize time and distance arrays to the above values using initialization lists.

2. Ask the user for some number of seconds between 0 and 18 inclusive. a. This should be a floating point data type, either float or double. b. If the user inputs a value outside that range, your program should print an error message and give the user the chance to enter another number.

3. Determine where on the time scale the inputted number resides. a. For example, if the user inputs the number 11, that resides between the time values of 10 and 12. CS1325 Introduction to Programming page: 4

4. Calculate the interpolated result for y (meters) using linear interpolation and print the result on the screen.

5. Give the user the chance to enter another number if desired.

Functional and Other Requirements: Besides the main() function, your program should, at minimum, contain the following function. Note that the exact specifications for the input parameters were deliberately not provided as part of the exercise. double getPosition (, , , ); This function will first scan through the time array to determine which points constitute the end points with respect to the calculation, i.e., the (xi , yi) and (xi+1, yi+1) points in the above equation. It will then calculate the interpolated value of y according to the equation above, and return the result as a double. Note that because of the way the formula works, if the user enters a value that is exactly equal to a time value in the array, the function should just return the corresponding y (meters) value. This includes the endpoints. For example, if the user enters an 18, the function should return the value 18. If the user inputs 0, just return a 2. The program should be able to accept multiple inputs from the user without having to stop and restart the program every time. After a given distance value is reported, have the program ask the user if he/she wants to continue. If yes, then get another time value from the user. If not, then exit the program.

THIS PROGRAM MUST BE COMPLETED IN C: The technique of interpolation canbe used for estimating values between data points. The simplest method ofinterpolation is called linear interpolation, shown in the following figure. In thiscase, two adjacent points are connected with a straight line. In a

Program 2 - Linear Interpolation The technique of interpolation can be used for estimating values between data points. The simplest method of interpolation is called linear interpolation, shown in the following figure. In this case, two adjacent points are connected with a straight line (X1+1, Yi+1 (Ki Y) Figure 4.5 Linear interpolation. The value of y for any x between two adjacent points (xi, y) and (Xi+l, yi+) is given by the following equation: Vi+1 (x - xi) Xi1 Program 2 - Linear Interpolation The technique of interpolation can be used for estimating values between data points. The simplest method of interpolation is called linear interpolation, shown in the following figure. In this case, two adjacent points are connected with a straight line (X1+1, Yi+1 (Ki Y) Figure 4.5 Linear interpolation. The value of y for any x between two adjacent points (xi, y) and (Xi+l, yi+) is given by the following equation: Vi+1 (x - xi) Xi1

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!