Project - Data Handling and Interpolation
What is interpolation ?
Interpolation is a method of fitting the data pints to represent the value of a function. It has various applications in engineering and science, that are used to construct new data points within the range of a discrete data set of known data points or can be used for determining a formula of the function that will pass from the given set of points(x,y).
Type of interpolation methods are:
1) Linear interpolation
2) nearest neighbor interpolation or piecewise constant interpolation
3) Polynomial interpolation
5) Mimetic interpolation
6) Cubic Spline interpolation
1) Linear interpolation :
A linear interpolation is a form of interpolation, which involves the generation of new values based on an existing set of values. Linear interpolation is achieved by geometrically rendering a straight line between two adjacent points on graph or plane. All points on the line other than the original two can be considered interpolated values.
Linear interpolation formula
The formula to calculate linear interpolation is:
Linear interpolation (y) = y1+(x-x1)(y2-y1)(x2-x1)y1+(x-x1)(y2-y1)(x2-x1)
were,
- x1x1 and y1y1 are the first coordinates
- x2x2 and y2y2 are the second coordinates
- x is the point to perform the interpolation
- y is the interpolated value
2) Nearest neighbor interpolation or piecewise constant interpolation
Interpolation is the problem of approximating the value of a function for a non given point in some space when given the value of that function in points around that point. The nearest neighbor algorithm selects the value of the nearest point and does not consider algorithm selects the value of the nearest point and does not consider the values of neighboring points at all , yielding a piecewise-constant interpolant.
3) Polynomial interpolation
Polynomial interpolation is a method of estimating values between known data points. When graphical data contains a gap, but data is available on either side of the gap or at a few specific points within the gap, an estimate of values within the gap can be made by interpolation.
4) Spline interpolation
Spline interpolation similar to the polynomial interpolation x uses low degree polynomial in each of the intervals and chooses the polynomial pieces such that they fit smoothly together. The resulting function is called a spline.
5) Mimetic interpolation
mimetic interpolation is a method for interpolating differential forms. In contrast to other interpolation methods, which estimate a field at a location given its values on neighboring points, mimetic interpolation estimates the field's k{\displaystyle k} Kk-form given the field's projection on neighboring grid elements. The grid elements can be grid points as well as cell edges or faces, depending on k=0,1,2, 3…{\displaystyle k=0,1,2,\cdots }.
Mimetic interpolation is particularly relevant in the context of vector and pseudo-vector fields as the method conserves line integrals and fluxes, respectively
6) Cubic Spline interpolation
Cubic spline interpolation is a special case for Spline interpolation that is used very often to avoid the problem of Runge's phenomenon. This method gives an interpolating polynomial that is smoother and has smaller errors than some other interpolating polynomials such as Lagrange polynomial and Newton polynomial.
Project answer
clear;
clc
%Interpolation of voltage and current data
%reading Excel file data
D=xlsread('VI');
V=D(:,1);%voltage data seperating
i=D(:,2);%current data seperating
xq = -17.3:0.1:0.9% given interpolation range
yq1=interp1(V,i,xq);%linear interpolation
yq2=interp1(V,i,xq,"spline");%spline interpolation
figure(1);
plot(V,i,'s',xq,yq1,':.'); %linear interpolation plotting
title('linear interpolation');
xlabel('volatge(v)');
ylabel('current(i)');
legend('Actual value', 'interpolated value', 'location', 'northeast');
grid on;
% spline interpolation plotting
figure(2);
plot(V,i,'s',xq,yq2,'b: .');
title('spline interpolation')
xlabel('volatge(v)');
ylabel('current(i)');
legend('Actual value', 'interpolated value', 'location', 'northeast');
grid on;
%saving the interpolation data into a text file
vol_cu=fopen('VI.output.txt','w');
fprintf(vol_cu,'voltage current\n');
% writing voltage and current value
fprintf(vol_cu,'%4.3f %5.5f\n',xq,yq2);
%savaing linear interpolation graph
savefig(1,'vilinear.fig');
%savaing spline interpolation graph
savefig(2,'vispline,fig');
fclose(vol_cu);