slides - problem solving with excel and matlab - university of

18
Interpolation Jake Blanchard University of Wisconsin - Madison Spring 2008

Upload: others

Post on 12-Feb-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Slides - Problem Solving with Excel and Matlab - University of

Interpolation

Jake Blanchard

University of Wisconsin - Madison

Spring 2008

Page 2: Slides - Problem Solving with Excel and Matlab - University of

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

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

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

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

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

Piecewise linear interpolation

Connect each data point by a straight line

Page 8: Slides - Problem Solving with Excel and Matlab - University of

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

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

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

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

Matlab functions

interp1 – 1-D linear interpolation

interp2 – 2-D linear interpolation

Page 13: Slides - Problem Solving with Excel and Matlab - University of

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

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

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

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

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

Questions?