Lecture9 Interpolation
Lecture9 Interpolation
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).
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.
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)
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.
Interpolat on Steps
x = ...
y = ...
xnew = ...
6
Interpolat on method names n
the nterp1 command
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
8
Program
x = 0:5; %Original time vector
y = [0 10 25 36 52 59]; %Original velocity vector
10