Exercise 7 Matlab PDF
Exercise 7 Matlab PDF
INTERPOLATION
DRILL #7
NAME
:
_______________________________
COURSE
:
_______________________________
SECTION :
_______________________________
DATE OF PERFROMANCE
:
________________
DATE OF SUBMISSION
:
________________
_______________________________________
INSTRUCTOR
1
Objectives
The exercise aims to give students the opportunity to be familiar with the different
interpolation functions available in Matlab
Discussion
Interpolation is a method of constructing new data points within the range of a discrete set
of known data points from a range of data points.
It is also defined as an approximation of a complicated function by a simple function using
the techniques such as Curve Fitting and Regression Analysis. There are several types of
interpolations and they are:
interp1q
interp2
interp3
interpft
interpn
spline
Example 1:
x=[1,2,3,4,5,6,7,8,9,10]
Y=[0,2,4,6,8,10,12,14,16,18]
Xi=[1.25,1.5,1.75]
Yi=interp1(Y,5)
Yi=interp1(x,Y,5)
Yi=interp1(x,Y,xi)
Yi=interp1(x,Y,spline)
Example 2:
X,Y] = meshgrid(-3:.25:3);
Z = peaks(X,Y);
[XI,YI] = meshgrid(-3:.125:3);
ZI = interp2(X,Y,Z,XI,YI);
mesh(X,Y,Z), hold, mesh(XI,YI,ZI+15)
hold off
axis([-3 3 -3 3 -5 20])
Example 3:
table =
1950
150.697
1960
179.323
1970
203.212
1980
226.505
1990
249.633
p = interp1(table(:,1),table(:,2),1975)
p = 214.8585
Questions
Give applications of interpolation other than those given in the discussion (give two)?
What is the default interpolation method used in Matlab? Why this method?
If you include extrapval as an argument in you interpolation function, what does it do?
Exercises:
1. Create 2 arrays (A and B) of size n filled with user input data. Ask the user for a value of
and compare it to the values of A, if there, find the corresponding value in B. IF the value
is only within the range of values in A then interpolate the corresponding value based on
array B.
2. Create another program this time with array C also with user input data. From a user
input numbers Ai and Bi interpolate for the value of Ci.
Program Listing