Engineering 7:
Prof. Alexandre Bayen
Introduction to Programming for Engineers
Spring 2011
Lab 8: Interpolation and Series
Date Assigned: 5:00pm, Friday – April 1.
Date Due: 5:00pm, Friday – April 8.
For the problems in this assignment, you should assume that all vector input and output arguments are column
vectors. Vectors defined by x and y are always the same size. Vectors defined by X and Y are always the same
size. You may assume that the values contained in x and X are unique and in ascending order. You may also
assume that the all the values of X are between min(x) and max(x), inclusively.
Problem 1:
Write a function with header []
= myInterpPlotter(x,y, X, option)
where
x
and
y
are column
vectors containing x and y data points, and
X
is a column vector containing the coordinates for which an
interpolation is desired. The input argument option should be a string either
‘linear’
,
‘spline’
,
‘nearest’
.
Your function should produce a plot of the data points (x,y) marked as red circles, and the points (X,Y) where
X
is the input vector, and
Y
is the interpolation at the points contained in
X
defined by the input argument specified
by option. The points (X,Y) should be connected by a blue line. Be sure to include title, axis labels, AND a
legend. Hint: You should use the function
interp1
.
Test Cases:
>> x = [0 .1 .15 .35 .6 .7 .95 1];
>> y = [1 0.8187 0.7408 0.4966 0.3012 0.2466 0.1496 0.1353];
>> myInterpPlotter(x,y, linspace(0,1,100), 'nearest')
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
nearest interpolation of data
x
y
data points
interpolation
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 HOROWITZ
 data points, Spline interpolation, Prof. Alexandre Bayen

Click to edit the document details