Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use interpolation methods to obtain missing information from a set of data point

ID: 3931401 • Letter: U

Question

Use interpolation methods to obtain missing information from a set of data points. Consider for this purpose the census data (population vs year), by calling in Matlab: Plot the data. Note that we know the population every 10 years, from 1790 to 1990. We shall obtain now the population for each year. Consider the vector dateI = cdate(1):cdate(end), i.e. from the first year to the last one, with sampling 1. Use the Matlab function interp1 to obtain the interpolated population. Two methods will be used: linear and spline interpolation. Plot your results. The function interp1 has an interesting optional parameter, 'extrap', which means extrapolation, i.e., looking into the future. Consider now extended the vector date E = [dateI cdate(end):2025], and extrapolate the data, via two methods: linear and spline. Please note that extrapolation is not the same as prediction, which is much more involved.

Explanation / Answer

The function used for interpolation is interp1(x, y, xq).

where x and y are the initial x and y and xq are the inner intervals.

By default this is linear interpolation.

To interpolate using a spline we just use 'spline' flag in the method.

therefore, spline_interpolation = interp1(x, y, xq, 'spline')

For extrapolation, we use the same method with an extra flag called 'extrap'.

Hence linear_extrapolation = interp1(x, y, xq, 'linear', 'extrap')

Hence spline_extrapolation = interp1(x, y, xq, 'spline', 'extrap')

Code

load census;

%declaring dateI to be all the years in between cdate range
dateI = cdate(1):cdate(end);

%plotting linear interpolation
figure
linear_interpolation = interp1(cdate, pop, dateI);
plot(cdate, pop, 'o', dateI, linear_interpolation, ':.');
title('Linear interpolation');

%plotting spline interpolation
figure
spline_interpolation = interp1(cdate, pop, dateI, 'spline');
plot(cdate, pop, 'o', dateI, spline_interpolation, ':.');
title('Spline interpolation');

%extrapolating
%dates after the end year for extrapolation
dateE= cdate(end):2025;

%plotting linear extrapolation
figure
linear_extrapolation = interp1(cdate, pop, dateE, 'linear', 'extrap');
plot(cdate, pop, 'o', dateE, linear_extrapolation, ':.');
title('Linear extrapolation');

%plotting spline extrapolation
figure
spline_extrapolation = interp1(cdate, pop, dateE, 'spline', 'extrap');
plot(cdate, pop, 'o', dateE, spline_extrapolation, ':.');
title('Spline extrapolation');