You are on page 1of 5

Si se conoce:

Xo f (2 )=0.6667
X 1 f (1 ) =1.3333
X 2 f ( 0 )=2.000
X 3 f ( 1 )=1.3333
X 4 f ( 2 )=0.6667

Hallar el polinomio de Lagrange y el valor aproximado de f(1,3)


L4 (x)=

1
xx 2
xx 3
xx 4
Yo+
( xxx
0x 1 )( x 0x 2 )( x 0x 3 )( x 0x 4 )
0
xx 2
xx 3
xx 4
Y 1+
( xxx
)(
)(
)(
1x 0 x 1x 2 x 1x 3 x 1x 4 )
x 0
xx 1
xx 3
x x 4
Y 2+
( xx2x
)(
)(
)(
0 x 2x 1 x 2x 3 x 2x 4 )
0
xx 1
xx 2
xx 4
Y 3+
( xxx
3x 1 )( x 3x 1 )( x 3x 1 )( x 3x 1 )
0
x x 1
xx 2
xx 3
Y4
( xxx
)(
)(
)(
4x 0 x 4x 1 x 4x 2 x 4x 3 )

L4(x)=

x(1)
x(0)
x (1)
x( 2 )
( 0.6667 ) +000 io de Lagrange y el valor aproximadode f ( )
( 2(1)
)(2(0)
)( 2(1)
)( 2
(2) )

x(2 )
x( 0 )
x( 1 )
x( 2 )
( 1.3333 ) +
1(2 ) 1( 0 ) 1( 1 ) 1( 2 )

x(2 )
0 (2 )

)(

x (1 )
0(1 )

)(

x( 1 )
0( 1 )

)(

x( 2 )
( 2.0000 ) +
0( 2 )

x(2 )
1(2 )

)(

x (1 )
1(1 )

)(

x( 0 )
1( 0 )

)(

x( 2 )
(1.3333 )+
1( 2 )

)(

x(2 )
2(2 )

)(

)(

x (1 )
2(1 )

)(

)(

x( 0 )
2( 0 )

)(

x( 1 )
(0.6667)
2( 1 )

L4 (x)= 0.111 x4 + 0.000 x3 + 0.7778 x3 0.000 x + 2


L4 (1,3)= 1.0022

PROGRAMA PARA MATLAB


function [C, L] = lagrange(X,Y)
%DATOS
%X es un vector que contiene la lista de abscisas
%Y es un vector que contiene la lista de ordenadas
%RESULTADOS
% C es la matriz que contiene los coeficientes del polinomio
% interpolador de Lagrange
% L es la matriz que contiene los coeficientes de los polinomios
% Li de Lagrange
w= length(X);
n=w-1;
L=zeros(w,w);
% FORMACION DE LOS POLINOMIOS Li DE LAGRANGE
for k=1: n+ 1
V=1;
for r=1:n+1
if k~=r
V = conv(V, poly(X(r)))/(X(k)-X(r));
end
end
L(k,:) = V
end
% CALCULO DE LOS COEFICIENTES DEL POLINOMIO INTERPOLADOR
C=Y*L;

COMAND WINDOW
>> X=-2:2;
CONDICIONES INICIALES

>> Y=4./(2+X.^2);

EJECUCION DEL PROGRAMA

>> [C, L] = lagrange(X,Y)


L=
0.0417 -0.0833 -0.0417

0.0833

L=
0.0417 -0.0833 -0.0417
-0.1667

0.1667

0.0833

0.6667 -0.6667

L=
0.0417 -0.0833 -0.0417
-0.1667

0.1667

0.2500

0.0833

0.6667 -0.6667

0 -1.2500

1.0000

L=
0.0417 -0.0833 -0.0417
-0.1667

0.1667

0.0833

0.6667 -0.6667

0.2500

0 -1.2500

-0.1667 -0.1667
0

0.6667
0

1.0000

0.6667

L=
0.0417 -0.0833 -0.0417
-0.1667
0.2500

0.1667

0.6667 -0.6667

0 -1.2500

-0.1667 -0.1667
0.0417

0.0833

0.6667

1.0000

0.6667

0.0833 -0.0417 -0.0833

C=
0.1111 -0.0000 -0.7778

2.0000

L=
0.0417 -0.0833 -0.0417
-0.1667
0.2500

0.1667

0.6667 -0.6667

0 -1.2500

-0.1667 -0.1667
0.0417

0.0833

0.6667

1.0000

0.6667

0.0833 -0.0417 -0.0833

GRAFICA DE LA FUNCION
>> x=-2:0.01:2;
y=4./(2+x.^2);
y1=polyval(C,x);
plot(x,y,'k',x,y1,'r')

COEFICIENTES DEL POLINOMIO


DE LAGRANGE

LAGRANGE PARA X=1.3


>> polyval(C,1.3)
ans = 1.00290
1.00290

VALOR APROXIMADO POR INTERPOLACION


DE LAGRANGE

You might also like