Slides - Problem Solving with Excel and Matlab - University of
Transcript of Slides - Problem Solving with Excel and Matlab - University of
![Page 1: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/1.jpg)
Interpolation
Jake Blanchard
University of Wisconsin - Madison
Spring 2008
![Page 2: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/2.jpg)
Case Study
You’ve taken data for measured
temperature as a function of time from a
hot water faucet
![Page 3: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/3.jpg)
Data
Time (s) Temperature (F)
0 72.5
1 78.1
2 86.4
3 92.3
4 110.6
5 111.5
6 109.3
7 110.2
8 110.5
9 109.9
10 110.2
![Page 4: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/4.jpg)
Questions
Estimate temperature at t=0.6, 2.5, 4.7,
and 8.9 seconds
Estimate time it will take to reach T=75,
85, 90, and 105 degrees
![Page 5: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/5.jpg)
Interpolation
Defining a function that takes on specified
values at specified points
Unlike curve fits, interpolation always
goes through the data points
Generally piece-wise, rather than covering
entire range
Often, first approach is to draw straight
lines between points
![Page 6: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/6.jpg)
Polynomials
For N data points, there is a unique
polynomial (usually of order n-1) that
goes through each point
This is an interpolating polynomial,
because it goes exactly through each data
point
Problem: between data points, function can
vary by large amount
![Page 7: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/7.jpg)
Piecewise linear interpolation
Connect each data point by a straight line
![Page 8: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/8.jpg)
Piecewise Cubic Interpolation
Goes through data points and has
continuous first and second derivative
from piece to piece
![Page 9: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/9.jpg)
Shape-Preserving Interpolation
Can be thought of as “visibly appealing”
Abandon continuous second derivative
Try to avoid large deviation between
points
![Page 10: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/10.jpg)
Example
0 1 2 3 4 5 6 7 8 9 1030
40
50
60
70
80
90
100
110
120
Time (s)
Tem
pera
ture
(F
)
data 1
spline
shape-preserving
10th degree
![Page 11: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/11.jpg)
Without Polynomial
0 1 2 3 4 5 6 7 8 9 1070
75
80
85
90
95
100
105
110
115
Time (s)
Tem
pera
ture
(F
)
data 1
spline
shape-preserving
![Page 12: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/12.jpg)
Matlab functions
interp1 – 1-D linear interpolation
interp2 – 2-D linear interpolation
![Page 13: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/13.jpg)
1-D interpolation
yi = interp1(x,y,xi,’linear’)
yi = interp1(x,y,xi,’cubic’) – shape-
preserving
yi = interp1(x,y,xi,’spline’)
x,y=data vectors
xi is vector of interpolation points
![Page 14: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/14.jpg)
Script
time=0:10;
temps=[72.5 78.1 86.4 92.3 110.6 111.5 109.3 110.2 110.5 109.9 110.2];
plot(time,temps,'o')
xlabel('Time (s)')
ylabel('Temperature (F)')
plotvals=0:0.1:10;
yvals=interp1(time,temps,plotvals,'linear')
hold on
plot(plotvals,yvals)
yvals=interp1(time,temps,plotvals,'cubic')
plot(plotvals,yvals,'r')
yvals=interp1(time,temps,plotvals,'spline')
plot(plotvals,yvals,'g')
![Page 15: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/15.jpg)
Practice
Computer controlled machines are used
to shape a car fender
The points on the next slide define the
fender
Use interpolation to define the entire
fender
![Page 16: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/16.jpg)
Fender Data
X
(ft)
0 .25 .75 1.25 1.5 1.75 1.875 2 2.125 2.25
Y 1.2 1.18 1.1 1 0.92 0.8 0.7 0.55 0.35 0
![Page 17: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/17.jpg)
Practice – Trace of My Hand
Download and run handdata.m
Plot x vs. y
Let t=1:76
Interpolate x vs. t and y vs. t
Now plot curve for hand vs. data
![Page 18: Slides - Problem Solving with Excel and Matlab - University of](https://reader031.fdocuments.us/reader031/viewer/2022021305/620731dd49d709492c2ede81/html5/thumbnails/18.jpg)
Questions?