Académique Documents
Professionnel Documents
Culture Documents
3 2
y= A x +B x +Cx+ D
C=inv(A'*A)*(A'*y')
C=
0.0266
-0.2751
2.7387
-1.7401
>>u=1:0.01:6.8;
>> v=0.0266*u.^3-0.2751*u.^2+2.7387*u-1.7401;
>> plot(u,v,'r')
>> plot(x,y,'*b)
>> plot(u,v,'r')
14
12
10
0
1 2 3 4 5 6 7
--------------------------------------------------
x=[1 2 5.6];
>> C=inv(A'*A)*(A'*y')
C=
0.0234
0.5938
-0.3125
0.9688
>> u=1:0.01:5.6;
>> v=C(1)*u.^3+C(2)*u.^2+C(3)*u+C(4);
>> plot(u,v,'r')
>> hold on
>> plot(x,y,'*b')
25
20
15
10
0
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
INTERPOLACION MATRICIALMENTE
X 1 2 2.4 5.6
Y 1 1.5 4.8 9.5
y= A x 3 +B x 2 +Cx+ D
C=inv(A'*A)*(A'*y')
C=
-1.6129
14.2454
-30.9459
19.3134
>>u=1:0.01:5.6;
>> v=C(1)*u.^3+C(2)*u.^2+C(3)*u+C(4);
>> plot(u,v,'r')
>> hold on
>> plot(x,y,'*b')
25
20
15
10
-5
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
>>x=1;
poly(x)
>>x=[1 2];
poly(x)
>>x=[1 2 3];
poly(x)
ans =
1 7 10
>> conv(v,w)
ans =
2 10 18 18
0.9
0.8
0.7
0.6
0.5
0.4
function [C,L]=lagrange(X,Y)
%DATOS:
%X: Vector columna de abscisas
%Y: Vector column de ordenadas
%RESULTADOS
%C: Matriz que contiene los coeficientes del polinomio interpolador de
%Lagrange
%L: Matriz que contiene los coeficientes de los polinomios de Lagrange
w=length(X);
n=w-1;
%Formacion de los coeficientes del polinomio interpolador de lagrange
for k=1:w
V=1;
for j=1:w
if k~=j
V=conv(V,poly(X(j)))/(X(k)-X(j));
end
end
L(k,:)=V;
end
%Calculo de coeficientes del polinomio interpolador de Lagrange
C=Y*L