37. Interpolation

37. Interpolation - Interpolation For an introduction to...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
©2009 by L. Lagerstrom Interpolation • For an introduction to the basic concepts, see the associated video clip • Linear interpolation • Multiple values and out-of-range values • Multiple data sets • Cublic spline interpolation • Which is better: linear or cubic spline? • Extrapolation • Nearest neighbor interpolation • Versions of interp1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Matlab code Command window display ©2009 by L. Lagerstrom Linear Interpolation %Linear interpolation: Given a %set of (x,y) data, we can estimate %the y value for a certain x value %that's not part of the data set %by connecting the two nearest data %points with a straight line. %Some sample data x = 0:5 y = [0 20 60 68 77 110] %Interpolate a y value for x = 2.6 %using the interp1 function. %(Note: the "1" in interp1 indicates %one variable; Matlab also has an %interp2 function for functions of %two variables, but we won't cover %it.) yi = interp1(x,y,2.6) x = 0 1 2 3 4 5 y = 0 20 60 68 77 110 yi = 64.80
Background image of page 2
Matlab code Command window display ©2009 by L. Lagerstrom Multiple Values and Out-of-Range Values %We can also interpolate for %multiple x values at the same time %by using a row vector: %Redisplay x and y for reference x = 0:5 y = [0 20 60 68 77 110] %Interpolate for x = 2.6 and 4.9 xi = [2.6 4.9] yi = interp1(x,y,xi) %Note that interpolation cannot %be done outside the range of the %given data set. The max value in %x is 5, so interpolating for 5.1 %is undefined ("not a number"): yi = interp1(x,y,5.1) x = 0 1 2 3 4 5 y = 0 20 60 68 77 110 xi = 2.60 4.90 yi = 64.80 106.70 yi = NaN
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Command window display ©2009 by L. Lagerstrom Multiple Data Sets %The data in y may also be an array, %in which case the interp1 function %will interpolate a value for each %column of data. That is, each %column represents a set of data %points for the same set of x %values. Consider, for example, %three sets of temperature readings %at one second intervals: %Time (s) Temp 1 Temp 2 Temp 3 % 0 0 0 0 % 1 20 25 52 % 2 60 62 90 % 3 68 67 91 % 4 77 82 93 %Store the time and temperature data t = (0:4)'; T(:,1) = [0 20 60 68 77]'; T(:,2) = [0 25 62 67 82]'; T(:,3) = [0 52 90 91 93]';
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/23/2010 for the course ENG 42325 taught by Professor Lagerstrom during the Spring '10 term at UC Davis.

Page1 / 13

37. Interpolation - Interpolation For an introduction to...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online