Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Matemticas de la Especialidad
Ingeniera Elctrica
Funciones de interpolacin
y aproximacin
Jos Luis de la Fuente OConnor
jldelafuente@etsii.upm.es
joseluis.delafuente@upm.es
Clase_interpolacin_aproximacin_funciones_2014.pdf
1/57
ndice
Introduccin
Interpolacin polinmica
Polinomios de Lagrange
Polinomios de Newton
Polinomios Ortogonales
Interpolacin de Hermite
Interpolacin por splines cbicas
2/57
TY OF TECHNOLOGY
Introduccin
al Interpolation
40
60
80
20
km/h
80 100
12
0
0
1
120
0
4
kmh
100
11 12 1
10
2
9
3
4
8
7
5
6
Why Splines?
nterpolation
tru
m
gr
sm
ho
sm
ke
sp
ba
int
T. Gambill (UIUC)
CS 357
La interpolacin
tiene como objeto, en general, la obtencin de nuevos
e contain
our interpolation?
puntos a partir del conocimiento de un conjunto discreto de ellos.
4/57
to plot una
a smooth
curveque
(a continuous
differentiable
function)
La idea Ies Try
obtener
funcin
se verifique
en todos
los puntos conocidos y
connecting these discrete points.
que permita
calcular tantos nuevos como se desee.
experimento
en el technique
que se han
obtenidoy at
unx conjunto
de puntos
We use interpolation
to estimate
where theres
no data.
.x; y/.
Datos
knownconocidos
data
Cul is
esthe
el valor de
What
y que corresponde
a
corresponding
value
of
y for
este
x? this x ?
5/82
La interpolacin se puede
como lo inverso de la evaluacin de una funcin.
BASIC ver
IDEAS
a
10
5/57
Por ejemplo, aproximar una funcin para evitar tener que evaluar su
complicada expresin: la de la distribucin normal estndar,
1
N.x/ D p
2
y 2 =2
dy:
InterpolacinInterpolation
vs. aproximacin
o ajuste.
v.s. Curve
Fitting
known
data
Datos conocidos
curve
fit aproximada
Funcin
interpolation
Interpolacin
x
x
Curve fitting:
fit function
data notuna
exactly
agree o el
El ajuste,
en general,
busca &predecir
tendencia
de datospasses
de acuerdo
un modelo
En general, comportamiento
Interpolation: function
exactlycon
through
known dado;
data
la interpolacin, que la funcin, o funciones, a que de lugar incluya
la aproximacin o ajuste busca predecir una tendencia, o el
todos los datos conocidos, habitualmente buenos.
8/83
Interpolation
& funcin,
Extrapolation
la interpolacin
que la
o funciones, a que de lugar incluya todos los
datos conocidos,
habitualmente
buenos.
Interpolation
approximate within
the range of independent variable
a
10
7/57
f .x/ D
n
i
cj j .x/:
j D1
cj j .xi / D f .xi /;
i D 1; : : : ; m:
j D1
Este sistema:
Si m > n, lo normal es que sea incompatible y habra que resolverlo
pause
p = polyfit(xdat,ydat,2)
xvet=1:0.1:50;
plot(xvet,polyval(p,xvet))
hold on
0.3544
-0.0529
0.6705
-0.6192
pause
p = polyfit(xdat,ydat,4)
plot(xvet,polyval(p,xvet))
-1
10
15
20
25
30
35
40
45
50
10/57
11/57
Interpolacin polinmica
Teorema principal de la interpolacin polinmica Sean .x1; y1/, .x2; y2/,
: : : ; .xn; yn/ n duplas de puntos con distintas xi . Existe un polinomio, y slo
uno, P , de grado n 1 o menor, que satisface P .xi / D yi , i D 1; : : : ; n.
cj j .xi / D f .xi /;
i D 1; : : : ; n;
j D1
12/57
Ao
x 2007 2008 2009 2010 2011 2012
Precio y 133,5 132,2 138,7 141,5 137,6 144,2
year=[2007 2008 2009 2010 2011 2012];
precio=[133.5 132.2 138.7 141.5 137.6 144.2];
M = vander(year);
a = M\precio;
x=linspace(min(year),max(year));
p=polyval(a,x);
plot(year,precio ,o,x,p,-);
13/57
x1 = 2007:1:2012;
y = interp1(year,precio,x1,linear);
plot(year,precio,o,x1,y,-)
hold on
pause
146
ys = year-mean(year);
A = vander(ys);
a = A\precio;
ds = x - mean(year);
p = polyval(a,ds);
plot(year,precio,o,x,p,-);
144
142
140
138
136
134
132
130
128
2006
2006.5
2007
2007.5
2008
2008.5
2009
2009.5
2010
2010.5
2011
14/57
Polinomios de Lagrange
Si se tienen dos puntos .x1; y1/ y .x2; y2/, el polinomio lineal que los interpola
es
p1.x/ D c1 C c2x;
y1 x 2
x2
y2 x 1
x1
y c2 D
y2
x2
y1
:
x1
x
x1
x2
x
C y2
x2
x2
x1
D y1l1.x/ C y2l2.x/:
x1
son
n
Y
lj .x/ D
kD1
kj
n
Y
.x
.xj
xk /
j D 1; : : : ; n:
;
xk /
kD1
kj
lj .xi / D ij D
1 si i D j
0 si i j
i; j D 1; : : : ; n:
16/57
l2
l4
0.8
l3
0.6
l1
l5
lk(x)
0.4
0.2
0
0.2
0.4
0.6
0
0.1
0.2
0.3
0.4
0.5
x
0.6
0.7
0.8
0.9
15/83
10
17/57
18/57
El resultado es el de la figura.
6
6
2
1.5
0.5
0.5
1.5
19/57
145
140
135
130
2007
2008
2009
2010
2011
2012
20/57
Polinomios de Newton
El polinomio de interpolacin de Newton tiene la forma
j 1
j
.x
xk /;
j D 1; : : : ; n:
kD1
21/57
2.5
Newk(x)
1.5
1
2
0.5
3
4
5
0.5
0
0.2
0.4
0.6
0.8
1
x
1.2
1.4
1.6
1.8
22/57
22/58
Ejemplo
Sustituyendo
x2
x3
x1
x1
.x3
0
0
x1/.x3
32 3 2 3
c1
y1
5 4c25 D 4y25 :
x2 /
c3
y3
2
32 3 2
3
1 0 0
c1
27
41 2 05 4c25 D 4 15 ;
1 3 3
c3
0
cuya solucin es c D 27 13
p.x/ D
4T . El polinomio es pues
27 C 13.x C 2/
4.x C 2/x:
23/57
0
x2
x3
x1
x1
.x3
0
0
x1/.x3
32 3 2 3
c1
y1
5 4c25 D 4y25 ;
x2/
c3
y3
24/57
Si se divide la segunda fila por .x2 x1/ y la tercera por .x3 x1/ se llega a
2
2
1
40
0
0
1
1
y1
32 3 6
6 y2
0
c1
6
0 5 4c25 D 6
6 x2
6
x 3 x2
c3
4 y3
x3
y1/=.x2
7
y1 7
7
x1 7
7:
7
y1 5
x1
x1/.
y2
x2
y1
x1
y f x1; x3
y3
x3
y1
:
x1
25/57
3
2
32 3 2
y1
1 0
0
c1
6
7
40 1
0 5 4c25 D 4
f x1; x2
5:
0 0 x3 x2
c3
f x1; x3 f x1; x2
3
2
32 3 2
y1
1 0 0
c1
7
40 1 05 4c25 D 6
4 f x1; x2 5 ;
0 0 1
c3
f x1; x2; x3
donde
f x1; x2; x3
f x1; x3
x3
f x1; x2
x2
no trivial
f x2; x3
x3
f x1; x2
:
x1
26/57
Lo no trivial
f x1 ; x3
x3
f x1 ; x2
x2
D
D
y2 y1
x2 x1
y3 y1
x3 x1
x3
y3 y2
x3 x2
x2
C
y2 y1
x3 x2
.x3
x1 /
.x3
y3 y1
x3 x1
x2 /.x3
.y2 y1 /.x3 x2 /
.x2 x1 /.x3 x2 /
x3
y2 y1
x2 x1
x1 /
.y2 y1 /.x2 x1 /
.x2 x1 /.x3 x2 /
x1
y3
y2 C y2
y3 y2
x3 x2
x3
y1
.x3
x2 /.x3
y2 y1
x2 x1
x1
y2 y1
x2 x1
x2 C x2
.x3
x1 /
x1 /
f x2 ; x3
x3
f x1 ; x2
x1
f x1
c2 D
f x1; x2
y1
y2
x2
f x2; x3
c3 D f x1; x2; x3 D
x3
En general
f xi ; : : : ; xj D
y1
x1
f x1; x2
D
x1
f xiC1; : : : ; xj
xj
y3 y2
x3 x2
x3
y2 y1
x2 x1
x1
f xi ; : : : ; xj 1
:
xi
27/57
f ;
f ; ;
f ; ; ;
f x1; x2
x2 f x2
f x1; x2; x3
f x2; x3
x3 f x3
f x3; x4
x4 f x4
28/57
Ejemplo
3
2
0 2
y 3
13
4
5
3
0
2
f f ; f ; ; f ; ; ;
3
13
4
1
2
1
6
3
5
3
2
3
1
3
2
5
3
29/57
El polinomio es entonces
p3.x/ D 3 C 12 .x
D 3
1/ C 31 .x
16
10
x C x2
3
3
1/ x
3
2
2.x
1/ x
3
2
2x 3:
% n(x)*(x-x(k-1))+a_k-1
30/57
60
50
40
30
20
10
10
2
4
31/57
0.000000000000000
32/57
-3.333333333333334
0.333333333333333
-1.666666666666667
0
0
33/57
Polinomios Ortogonales
Otra base interesante para interpolacin es la del espacio vectorial de
polinomios ortogonales Pn.
hp; qi D
p.x/q.x/!.x/ dx;
hpi ; pj i D
1 para i D j
0 para i j:
34/57
1/=2; .5x 3
3x/=2;
70x 3 C 15x/=8; : : : ;
35/57
Funcin de peso
1
.1 x 2 / 1=2
.1 x 2 /1=2
.1 x/ .1 C x/ ; ; >
e x
2
e x
36/57
k pk 1.x/:
kPk 1.x/:
37/57
1; x; 2x 2
8x 4
1; 4x 3
3x;
8x 2 C 1; 16x 5
20x 3 C 5x; : : : ;
38/57
39/57
2i 1
;
xi D cos
2k
i D 1; : : : ; k
If we know a great deal about the function f , then we may be able to choose points so as
Losthepuntos
dewe
Chebyshev
lasinformation
abcisas deabout
los puntos
igualmente
espaciados
educe
error. If
dont haveson
such
the function,
however,
the best awe
o is lo
to largo
reducede
thelaproduct
(a). The Chebyshev
minimize the maximum valu
semicircunferencia
de radiopoints
1 en effectively
R 2.
he product (a).
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
1
0.8
0.6
0.4
0.2
0.2
0.4
0.6
0.8
igualmente
espaciados,
tieneChebyshev
ventajas interesantes.
ejemplo,
quiere in Figure
Recall
the process
for selecting
points over an Por
interval
[a, b], se
as shown
interpolar puntos de la funcin de Runge
1
2. To select N + 1 points, split the f
semicircle
.x/ D into N arcs of equal length.
1 C 25x 2
3. Project the arcs onto the x-axis, giving the following formula for each Chebyshev point x
en el intervalo 1; 1.
41/57
j
a+b ba
1.2
1
1.5
0.8
1
0.6
0.4
0.5
0.2
0
0
0.5
1
0.5
0.5
0.2
1
0.5
0.5
kD1
c0
ck
n
i
ck Tk .x/ D u0
xu1;
kD0
donde
un D cn; un 1 D cn 1 C 2xun y
uj D cj C 2xuj C1 uj C2; j D n
2; n
1; : : : ; 0:
43/57
Los dos programas que siguen calculan ese polinomio y lo evalan para
determinados puntos.
function u = chebpol_clenshaw(c,x)
n = length(c);
u = c(n)*ones(size(x));
if n > 1
ujp1 = u;
u = c(n-1)+2*x*c(n);
for j = n-2:-1:1
ujp2 = ujp1;
ujp1 = u;
u
= c(j)+2*x.*ujp1-ujp2;
end
u = u-x.*ujp1;
end
Si se utilizan con
>>
>>
>>
>>
f = @(x) 1./(1+25*x.^2);
[c,x] = chebpol_int(f,11);
t = -1:.01:1;
plot(t,f(t),b,t,chebpol_clenshaw(c,t),r,x,f(x),ok)
44/57
Da como resultado:
1.2
0.8
0.6
0.4
0.2
0.2
1
0.8
0.6
0.4
0.2
0.2
0.4
0.6
0.8
Una mejora consiste en interpolar cada intervalo entre datos mediante un nico
polinomio u otra funcin.
Interpolacin de Hermite
Esta interpolacin tiene en cuenta los valores de la funcin a aproximar por
interpolacin en puntos concretos y el de sus derivadas.
47/57
xi / C c.x
xi /2 C d.x
xi /2.x
xd /;
Necesitaremos calcular a, b, c y d .
La derivada del polinomio es
p 0.x/ D b C 2c.x
xi / C d 2.x
xi /.x
xd / C .x
a C b.xd
b D si
b C 2c.xd
xi / C c.xd
xi / C d.xd
xi / 2
xi /2 .
D yd
xi /2 D sd :
48/57
2
32 3 2 3
a
1
0
0
0
yi
6
76 7 6 7
1
0
0
60
7 6 b 7 6 si 7
6
76 7 D 6 7:
0
41 xi xd .xd xi /2
5 4 c 5 4yd 5
d
0
1
2.xd xi / .xd xi /2
sd
El que se requiera que interpolen esos n datos aade 2.n 1/ ecuaciones, pues
cada n
49/57
50/57
x = -3:3;
y = [-1 -1 -1 0 1 1 1];
t = -3:.01:3;
p = pchip(x,y,t);
plot(x,y,o,t,p,-)
legend(datos,pchip,3)
1
0.8
0.6
0.4
0.2
0
0.2
0.4
0.6
0.8
1
3
datos
pchip
2
3
51/57
1.
52/57
Splines represent an alternative approach to data interpolation. In polynomial interpolation, a single formula, given by a polynomial, is used to meet all data points. The idea of
splines is to use several formulas, each a low-degree polynomial, to pass through the data
points.
El ejemplo ms
simple
es unof aspline
en elin que
puntos a
The simplest
example
spline islineal,
a linear spline,
whichse
oneconectan
connects thelos
dotswith
segments. Assume that we are given a set of data points (x1 , y1 ), . . . , (xn , yn )
interpolarstraight-line
mediante
segmentos de recta.
with x1 < < xn . A linear spline consists of the n 1 line segments that are drawn
between neighboring pairs of points. Figure 3.12(a) shows a linear spline where, between
each neighboring pair of points (xi , yi ), (xi+1 , yi+1 ), the linear function y = ai + bi x is
En la figura
muestra
unpoints.
ejemplo
de data
spline
lineal
el mismo
spline
drawnse
through
the two
The given
points
in the ygure
are (1, 2),con
(2, 1),
(4, 4), cbica.
and (5, 3), and the linear spline is given by
y
(a)
(b)
Figure 3.12 Splines through four data points. (a) Linear spline through (1,2), (2,1),
(4,4), and (5,3) consists of three linear polynomials given by (3.15). (b) Cubic spline
through the same points, given by (3.16).
53/57
Como en el caso de Hermite, las splines cbicos para interpolar n puntos de una
funcin imponen 3n 4 condiciones, ms n
continuidad de la segunda derivada.
Las primeras y segundas derivadas en los extremos son iguales dos a dos, etc.
54/57
Ejemplo
Estudiemos la interpolacin de tres puntos .x1; y1/, .x2; y2/ y .x3; y3/.
Los polinomios de los dos tramos podran ser
p1.x/ D 1 C 2x C 3x 2 C 4x 3
p2.x/ D 1 C 2x C 3x 2 C 4x 3:
El que las cbicas pasen por los puntos dados impone las siguientes condiciones
1 C 2x1 C 3x12 C 4x13
1 C 2x2 C 3x22 C 4x23
1 C 2x2 C 3x22 C 4x23
1 C 2x3 C 3x32 C 4x33
D
D
D
D
y1
y2
y2
y3 :
55/57
Por definicin, se impone que las segundas derivadas en los extremos sean cero,
lo que hace que
23 C 64x1 D 0 y 23 C 64x3 D 0:
1 x1 x12 x13
61 x2 x22 x23
60 0 0 0
6
60 0 0 0
6
60 1 2x2 3x22
6
60 0 2 6x2
40 0 2 6x1
0 0
0
0
0 0
0 0
1 x2
1 x3
0 1
0 0
0 0
0 0
0
0
x22
x32
2x2
2
0
2
32 3
2 3
0
y1
1
6y27
0 7 6 2 7
6y 7
37 6 7
x2 7 63 7
6 37
37 6 7
6y47
x3 7 64 7
6 7
27 6 7 D 6 7 :
3x2
7 617 6 0 7
6x2 7 62 7
607
5
4
5
405
0
3
0
6x3
4
56/57
1.5
0.5
0.5
1.5
3
datos
pchip
spline
2
57/57