Imagine you have a table of data (x;, Y:) but you need to estimate values between those specific points. The data might be growth rates, chemical reaction rates, profits or even exper- imental data....


8.1


Imagine you have a table of data (x;, Y:) but you need to estimate values between those<br>specific points. The data might be growth rates, chemical reaction rates, profits or even exper-<br>imental data.<br>Thus you require an approximate function y(x) at for x values in the range covered by the x;<br>values provided. We can use an interpolation scheme to estimate values for y for intermediate<br>values of x that are between values listed in the table.<br>1.1 Given two points with co-ordinates (x1,y1) and (x2,y2), there is a unique straight line<br>connecting them of the form y = m + c, where m is the gradient and c is a constant. Write<br>down expressions for the coefficients, m and c, in terms of the co-ordinates of the points. This<br>is linear interpolation.<br>1.2 Write a float function called interpolate that takes two pairs of float coordinates and<br>an intermediate x value (a total of 5 float arguments: x1, yl, x2, y2 and x). The function<br>should return a y value based on the straight line fit of the points. Incorporate your function<br>into a file interp.cpp.<br>Consider if your function needs to check the input values in any way and add any checking<br>you consider necessary.<br>1.3 Testing: Write a short main function in a file called testinterp.cpp to test your<br>function. Note that you will need a Makefile that is able to combine the two files interp.cpp<br>and testinterp.cpp to generate the test program: testinterp.<br>Have your program print out (using cout) what your interpolate function returns. Run<br>your program for the following point and report the values:<br>(x1,y1)=(1, 8.57), (x2,y2)=(2, 10.28) and an r value of 1.25.<br>

Extracted text: Imagine you have a table of data (x;, Y:) but you need to estimate values between those specific points. The data might be growth rates, chemical reaction rates, profits or even exper- imental data. Thus you require an approximate function y(x) at for x values in the range covered by the x; values provided. We can use an interpolation scheme to estimate values for y for intermediate values of x that are between values listed in the table. 1.1 Given two points with co-ordinates (x1,y1) and (x2,y2), there is a unique straight line connecting them of the form y = m + c, where m is the gradient and c is a constant. Write down expressions for the coefficients, m and c, in terms of the co-ordinates of the points. This is linear interpolation. 1.2 Write a float function called interpolate that takes two pairs of float coordinates and an intermediate x value (a total of 5 float arguments: x1, yl, x2, y2 and x). The function should return a y value based on the straight line fit of the points. Incorporate your function into a file interp.cpp. Consider if your function needs to check the input values in any way and add any checking you consider necessary. 1.3 Testing: Write a short main function in a file called testinterp.cpp to test your function. Note that you will need a Makefile that is able to combine the two files interp.cpp and testinterp.cpp to generate the test program: testinterp. Have your program print out (using cout) what your interpolate function returns. Run your program for the following point and report the values: (x1,y1)=(1, 8.57), (x2,y2)=(2, 10.28) and an r value of 1.25.
Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here