Académique Documents
Professionnel Documents
Culture Documents
function[C,L]=lagrange(X,Y)
w=length(X);
n=w-1;
L=zeros(w,w);
for k=1:n+1
V=1;
for j=1:n+1
if k~=j
V=conv(V,poly(X(j)))/(X(k)-X(j));
end
end
L(k,:)=V;
end
C=Y*L;
Ejemplo 1
X=-3:3
X=
-3 -2 -1 0 1 2 3
>> Y=4./(1+X.^2)
Y=
Columns 1 through 4
0.4 0.8 2 4
Columns 5 through 7
2 0.8 0.4
>> [C,L]=lagrange(X,Y)
C=
Columns 1 through 4
Columns 5 through 7
-2.56 -2.92300905702092e-016 4
L=
Columns 1 through 4
Columns 5 through 7
0.00555555555555555 -0.0166666666666667 0
-0.075 0.15 0
0.75 -0.75 0
-1.36111111111111 -7.40148683083438e-017 1
0.75 0.75 0
-0.075 -0.15 0
0.00555555555555556 0.0166666666666667 0
>> X=[-3:2:3]
X=
-3 -1 1 3
>> Y=4./(1+X.^2)
Y=
0.4 2 2 0.4
>> [C,L]=lagrange(X,Y)
C=
0 -0.2 0 2.2
L=
>> X=-3:0.01:3;
>> Y=4./(1+X.^2);
>> Y1=polyval(C,X);
>> plot(X,Y,'k',X,Y1,'r')
>> grid on
s=polyval(C,1.8)
s=
1.552
X=[-3:3]
X=
-3 -2 -1 0 1 2 3
>> Y=4./(1+X.^2)
Y=
Columns 1 through 4
0.4 0.8 2 4
Columns 5 through 7
2 0.8 0.4
>> [C,L]=lagrange(X,Y)
C=
Columns 1 through 4
Columns 5 through 7
-2.56 -2.92300905702092e-016 4
L=
Columns 1 through 4
Columns 5 through 7
0.00555555555555555 -0.0166666666666667 0
-0.075 0.15 0
0.75 -0.75 0
-1.36111111111111 -7.40148683083438e-017 1
0.75 0.75 0
-0.075 -0.15 0
0.00555555555555556 0.0166666666666667 0
>> X=-3:0.01:3;
>> Y=4./(1+X.^2)
Y=
Columns 1 through 4
Columns 5 through 8
Columns 9 through 12
Columns 13 through 16
Columns 17 through 20
Columns 21 through 24
Columns 25 through 28
Columns 29 through 32
0.476281196418365 0.479380640212845 0.482509047044632
0.485666759752796
Columns 33 through 36
Columns 37 through 40
Columns 41 through 44
Columns 45 through 48
Columns 49 through 52
Columns 53 through 56
Columns 57 through 60
Columns 61 through 64
Columns 65 through 68
Columns 73 through 76
Columns 77 through 80
Columns 81 through 84
Columns 85 through 88
Columns 89 through 92
Columns 93 through 96
Column 601
0.4
>> Y1=polyval(C,X);
>> plot(X,Y,'k',X,Y1,'r')
>> grid on
>> s=polyval(C,1.8)
s=
0.643671040000002
>>
4
3.5
2.5
1.5
0.5
0
-3 -2 -1 0 1 2 3
6.ejemplo
X=[-2,6]
X=
-2 6
>> Y=X.^3-6*X.^2+8*X-2
Y=
-50 46
>> [C,L]=lagrange(X,Y)
C=
12 -26
L=
-0.125 0.75
0.125 0.25
>> X=-2:0.01:6;
>> Y=X.^3-6*X.^2+8*X-2;
>> Y1=polyval(C,X);
>> plot(X,Y,'k',X,Y1,'r')
>> grid on
50
40
30
20
10
-10
-20
-30
-40
-50
-2 -1 0 1 2 3 4 5 6