0% found this document useful (0 votes)
6 views

Lecture9 Interpolation

The document discusses interpolation methods for estimating unknown values between known data points. It explains linear and spline interpolation techniques using the interp1 command in MATLAB. An example problem interpolates vehicle velocity data at smaller time intervals and plots the results of linear and spline interpolation on the same figure.

Uploaded by

ceyda.duztas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Lecture9 Interpolation

The document discusses interpolation methods for estimating unknown values between known data points. It explains linear and spline interpolation techniques using the interp1 command in MATLAB. An example problem interpolates vehicle velocity data at smaller time intervals and plots the results of linear and spline interpolation on the same figure.

Uploaded by

ceyda.duztas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Lecture 9

Interpolat on

Interpolation
 Interpolation (between-appending) is the process of estimating
an unknown value of a function, in between two known values.
 Estimation for outside of boundaries is called extrapolation (prediction).

 Given a set of data that results from an experiment (simulation-based or


real-world data), we assume that there is some function f(x) that passes
through the data points.

 Interpolation method:
We search a function that allows us to approximate f(x),
such that the function values may be determined (estimated).
The interpolating function passes through the original data set.

 Polynomial Curve Fitting method:


We search a function that is a fit approximately to the original data points.
The approximating function does not have to pass through the original data set.

2
Example : Compar son of Interpolat on method
and Curve F tt ng method
• Suppose a data set of 10 random numbers are generated.
• Curve Fitting Method : polyfit command is used for a fifth degree polynomial fit.
• Interpolation Method : interp1 command is used for spline interpolation.

x = 1:10; % vector
% Generate 10 random numbers, whose max value s 10.
y = 10 * rand(1, 10); % vector
% Plot the original random points with connected lines on same figure
plot(x,y,'o', x,y)

p = polyfit(x,y,5)
xnew = 1 : 0.1 : 10 ;
ynew1 = polyval(p, xnew) ;
figure % Another figure window
% Plot the curve fitting on another figure
plot(x,y,'o', xnew, ynew1)

ynew2 = interp1(x,y, xnew, 'spline') ;


figure % Another figure window
% Plot the interpolation on another figure
plot(x,y,'o', xnew, ynew2)
3

Plott ngs on Separate F gure W ndows


 F gure1: Connect ng the or g nal random po nts d splays broken l nes.
 F gure2: The curve fitting method (polyf t command) does not pass through
all data points, but d splays an approx mate polynom al.
 F gure3: The spl ne nterpolat on ( nterp1 command) passes through all data points.

Connect ng the Curve F tt ng Interpolat on


or g nal po nts (polyf t command) ( nterp1 command)

4
The interp1 command
 Interpolation involves computing approximate values between endpoint values.
 One-dimensional interpolation :
 Independent variable x
 Dependent variable y
 The built-in interp1 command performs one-dimensional interpolation,
an important operation for data analysis.

ynew = interp1(x, y, xnew, method)

 ynew is the interpolated values vector.


 x is a vector of the same length containing the x points.
 y is a vector containing the values of a function.
 xnew is a vector containing the points at which to interpolate.

The method is an optional string specifying an interpolation method.
(Default method s 'l near'.)

Interpolat on Steps

 STEP1: Define the vectors x and y (containing original datas).

 STEP2: Define a new x vector, that includes the x values


for which we want to find the new y values.

 STEP3: Use the nterp1 command to calculate new y values.

x = ...

y = ...

xnew = ...

ynew = interp1 (x, y, xnew)

6
Interpolat on method names n
the nterp1 command

 Linear interpolation (method = 'linear')


This method fits a different linear function between each pair of existing
data points, and returns the value of the relevant function at the points
specified by xnew vector.
This is the default method for the interp1 command.

 Nearest neighbor interpolation (method = 'nearest')


This method sets the value of an interpolated point to the value of the
nearest existing data point.

 Spline interpolation (method = 'spline')


This method fits a different 3rd degree function between each pair of
existing data points.

Example Problem
 Suppose the following table is given, containing the measured velocities,
versus time datas of a veh cle.

T me Veloc ty
(seconds) (mph)
0 0
1 10
2 25
3 36
4 52
5 59

 Write a Matlab program to use the interp1 command, to estimate vehicle


velocities on the interval of [ 0 , 5 ] seconds, with steps of 0.01 seconds.
 Also plot the “Linear” interpolation and “Spline” interpolation
graphs as subplots on same figure window.

8
Program
x = 0:5; %Original time vector
y = [0 10 25 36 52 59]; %Original velocity vector

xnew = 0 : 0.01 : 5; %Step is 0.01


ynew_lin = interp1 (x,y, xnew, 'linear');
ynew_spl = interp1 (x,y, xnew, 'spline');

subplot(1,2,1); plot(x,y,'o', xnew, ynew_lin);


title('LINEAR INTERPOLATION');
xlabel('Time');ylabel('Velocity');

subplot(1,2,2); plot(x,y,'o', xnew, ynew_spl,'r');


title('SPLINE INTERPOLATION');
xlabel('Time');ylabel('Velocity');

Subplots of Interpolat ons


The sub-plotted f gures show that “L near” nterpolat on and “Spl ne”
nterpolat on graphs are very s m lar for the g ven dataset.

10

You might also like