Linear Interpolation (1D): Problem Description Linear interpolation is a method
ID: 638949 • Letter: L
Question
Linear Interpolation (1D): Problem Description
Linear interpolation is a method for estimating a data point that exists within the bounds
of two known data points. For example; if it is known that in 2002, 40% of all tax returns were filed electronically, and in 2008, 85% of all tax returns were filed electronically. Linear interpolation might be used to estimate what percentage of tax returns were filed electronically in the years between 2002 and 2008.
Quite simply, a line is drawn between the two known data points and the unknown points are assumed to exist on the line. Given two coordinates (x1, y1) and (x2, y2) the slope, and the y- intercept, of the line that connects the two points is
m = (y2 - y1) (x2 - x1) b = y1 - m * x1;
Using these values for m and b, and an x value of interest, unknown values of y are estimated using the equation for a line
y = mx + b
(a) Write a C program that:
(i) Prompts the user for two coordinates (x1, y1) and (x2, y2).
(ii) Prompts the user for an x value with which interpolation will be used to find its corresponding y value.
(iii) Display the estimate value of y using linear interpolation.
Explanation / Answer
*/ double HermiteInterpolate( double y0,double y1, double y2,double y3, double mu, double tension, double bias) { double m0,m1,mu2,mu3; double a0,a1,a2,a3; mu2 = mu * mu; mu3 = mu2 * mu; m0 = (y1-y0)*(1+bias)*(1-tension)/2; m0 += (y2-y1)*(1-bias)*(1-tension)/2; m1 = (y2-y1)*(1+bias)*(1-tension)/2; m1 += (y3-y2)*(1-bias)*(1-tension)/2; a0 = 2*mu3 - 3*mu2 + 1; a1 = mu3 - 2*mu2 + mu; a2 = mu3 - mu2; a3 = -2*mu3 + 3*mu2; return(a0*y1+a1*m0+a2*m1+a3*y2); }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.