Escolar Documentos
Profissional Documentos
Cultura Documentos
ENERO 28 DE 2015
Figura Dos. Ajuste por mnimos cuadrados de tabulacin de puntos a una funcin polinomica de segundo grado.
El error al ajustar un punto P(xi,yi) a una funcin polinomica de segundo orden de la forma y a bx cx 2 est
dado por:
Ei y i a bx i cx i2
Para despreciar el signo del error y evitar un clculo errado, se trabaja con el cuadrado del error as:
Ei2 ( y i a bx i cx i2 ) 2
E2
2
i
i1
E 2
0
a
n
(y a bx cx ) 0
2
i
i1
yi a
i1
a.n b
1 b
i1
i1
xi c
xi c
i1
i1
x i2
2
i
i1
y
i1
(1)
E 2
0
b
n
(y a bx cx )x
2
i
i1
x y a x b x
i i
i1
i1
xi b
i1
2
i
i1
x i2 c
i1
3
i
i1
x i3
i1
x y
i i
(2)
i1
E2
0
c
n
(y a bx cx )x
2
i
2
i
i1
x i2 y i a
i1
i1
x i2 b
i1
x i2 b
i1
x i3 c
x i3 c
i1
n
i1
x i4
4
i
i1
x y
2
i i
(3)
i1
n
xi
in1
2
xi
i1
x i2
yi
i 1
a i1
n
n
x i3 b x i y i
i 1
c in1
n
2
x i4
xi y i
i 1
i1
n
i 1
n
i 1
n
xi
2
i
3
i
i 1
Resolviendo matricialmente se encuentra el valor de los coeficientes a, b y c del polinomio de segundo orden
ajustado a los datos de la tabulacin.
Las ecuaciones de polinomios de ajuste de oren superior, se sacan por simple inspeccin, as:
POLINOMIO DE GRADO UNO: y a bx
n
xi
i1
xi
yi
i1
a i1
n
n
b
x i2 x i y i
i1
i1
n
xi
in1
2
xi
i1
x i2
yi
i 1
a i1
n
n
x i3 b x i y i
i 1
c in1
n
4
2
xi
xi y i
i 1
i1
n
i 1
n
i 1
n
xi
2
i
3
i
i 1
n
xi
in1
2
xi
in1
3
xi
i1
x x
x x
x x
i 1
n
i 1
n
x i3
yi
i 1
i1
n
a n
4
xi xiy i
b
i 1
in1
n
c
x i5 x i2 y i
i 1
d in1
x i3 y i
x i6
i1
i 1
i 1
n
xi
2
i
3
i
4
i
i 1
i 1
n
i 1
n
i 1
n
x i2
3
i
4
i
5
i
i 1
En el mtodo de ajuste por mnimos cuadrados, una forma de medir la exactitud de la correlacin de los valores
tabulados y la funcin polinomica ajustada es por medio del coeficiente R, que relaciona el ajuste de los datos
tabulados y la funcin ajustada con respecto al valor de la media, as:
n
f (x i ) y2
i1
n
(y y)
i
, y
i1
i1
VALOR DE R
OBSERVACION
CORRELACION MODERADA
R = 1.0
CORRELACION EXACTA
El cdigo en MATLAB de la funcin de ajuste por mnimos cuadrados lineal, cuadrtica y cubica es el siguiente:
%
% FUNCION DE AJUSTE POR MINIMOS CUADRADOS LINEAL CUADRATIC0 Y CUBICO
% ELABORADA POR RAFHAEL ANDRES LUNA TEZNA
%
function [al,bl,fxl,R2l,REl REml,as,bs,cs,fxs,R2s,REs REms,ac,bc,cc,dc,...
fxc,R2c,REc,REmc ] = minc(xi,yi)
n=length(xi);
ym = mean(yi);
% AJUSTE LINEAL
Al = [n sum(xi);sum(xi) sum(xi.^2)];
vl = [sum(yi);sum(xi.*yi)];
xl = inv(Al)*vl;
al = xl(1,1);
bl = xl(2,1);
fxl = al+bl*xi;
REl = yi-fxl;
REml = mean(REl.^2);
R2l = sum((fxl-ym).^2)/sum((yi-ym).^2);
% AJUSTE CUADRATICO
As = [n sum(xi) sum(xi.^2);sum(xi) sum(xi.^2) sum(xi.^3); sum(xi.^2)...
sum(xi.^3) sum(xi.^4)];
vs = [sum(yi);sum(xi.*yi);sum((xi.^2).*yi)];
xs = inv(As)*vs;
as = xs(1,1);
bs = xs(2,1);
cs = xs(3,1);
fxs = as+bs*xi+cs*xi.^2;
REs = yi-fxs;
REms = mean(REs.^2);
R2s = sum((fxs-ym).^2)/sum((yi-ym).^2);
% AJUSTE CUBICO
Ac = [n sum(xi) sum(xi.^2) sum(xi.^3);sum(xi) sum(xi.^2) sum(xi.^3)...
sum(xi.^4);sum(xi.^2) sum(xi.^3) sum(xi.^4) sum(xi.^5);sum(xi.^3)...
sum(xi.^4) sum(xi.^5) sum(xi.^6)];
vc = [sum(yi);sum(xi.*yi);sum((xi.^2).*yi);sum((xi.^3).*yi)];
xc = inv(Ac)*vc;
ac
bc
cc
dc
=
=
=
=
xc(1,1);
xc(2,1);
xc(3,1);
xc(4,1);
fxc = ac+bc*xi+cc*xi.^2+dc*xi.^3;
REc = yi-fxc;
REmc = mean(REc.^2);
R2c = sum((fxc-ym).^2)/sum((yi-ym).^2);
num2str(cc),'*X^2+',num2str(dc),'*X^3'])
disp(['PROMEDIO DEL CUADRADO DE LOS RESIDUOS: ',num2str(REmc)])
disp(['FACTOR DE CORRELACION R2: ',num2str(R2c)])
disp('===================================================================')
% PRESENTACION GRAFICA DE RESULTADOS
figure
subplot(2,1,1)
plot(x,y,'ro',x,fxl,'b')
grid on
title('AJUSTE LINEAL POR MINIMOS CUADRADOS')
xlabel('x'), ylabel('y')
legend(': DATOS TABULADOS',[': Y= ',num2str(al),'+',...
num2str(bl),'*X
R^2 : ',num2str(R2l)])
subplot(2,1,2)
plot(x,REl,'go')
grid on
title('RESIDUOS DEL AJUSTE LINEAL POR MINIMOS CUADRADOS')
xlabel('x'), ylabel('RESIDUOS')
figure
subplot(2,1,1)
plot(x,y,'ro',x,fxs,'b')
grid on
title('AJUSTE CUADRATCO POR MINIMOS CUADRADOS')
xlabel('x'), ylabel('y')
legend(': DATOS TABULADOS',[': Y= ',num2str(as),'+',...
num2str(bs),'*X+',num2str(cs),'*X^2
R^2 : ',num2str(R2s)])
subplot(2,1,2)
plot(x,REs,'go')
grid on
title('RESIDUOS DEL AJUSTE CUADRATICO POR MINIMOS CUADRADOS')
xlabel('x'), ylabel('RESIDUOS')
figure
subplot(2,1,1)
plot(x,y,'ro',x,fxc,'b')
grid on
title('AJUSTE CUBICO POR MINIMOS CUADRADOS')
xlabel('x'), ylabel('y')
legend(': DATOS TABULADOS',[': Y= ',num2str(ac),'+',num2str(bc),'*X+',...
num2str(cc),'*X^2+',num2str(dc),'*X^3
R^2 : ',num2str(R2c)])
subplot(2,1,2)
plot(x,REc,'go')
grid on
title('RESIDUOS DEL AJUSTE CUBICO POR MINIMOS CUADRADOS')
xlabel('x'), ylabel('RESIDUOS')
Figura Cuatro. Ajuste por mnimos cuadrados de tabulacin de puntos a una funcin polinomica de primer orden.
Figura Cinco. Ajuste por mnimos cuadrados de tabulacin de puntos a una funcin polinomica de segundo orden.
Figura Seis. Ajuste por mnimos cuadrados de tabulacin de puntos a una funcin polinomica de tercer orden.
De acuerdo a los valores de R encontrados para cada una de las aproximaciones, se tiene:
APROXIMACION
VALOR DE R
OBSERVACION
LINEAL
0.6836
CORRELACION MODERADA
CUADRATICA
0.87982
CUBICA
0.92691
De lo anterior se puede concluir que entre las funciones trabajadas, la funcin polinomica de tercer orden o
cbica es la que mejor se ajusta a los datos tabulados.
= 0:ht:(mt-1)*ht;
% VECTOR DE FRECUENCIA
fi
ff
hf
= 0.1;
= 6;
= 0.1;
= fi:hf:ff;
grid on
title('GAFICA TRIDIMENSIONAL COEFICIENTES ANALISIS WAVELET')
xlabel('TIEMPO [seg]'), ylabel('FRECUENCIA [Hz]'), zlabel('C')
% GRAFICA WAVELET MAP
Figure
surf(t,f,wv,'FaceColor','interp','EdgeColor','none','FaceLighting',...
'phong')
colormap jet;
grid on
title('GRAFICA WAVELET MAP')
xlabel('TIEMPO [seg]'), ylabel('FRECUENCIA [Hz]'), zlabel('C')
view([0 90])
% GRAFICA SKELETON DEL ANALISIS WAVELET
pc = 30;
wv1=wv(1:pc,:);
wv2=wv(pc+1:2*pc,:);
for i=1:mt
max1 = max(wv1(:,i));
pos
= find(wv1(:,i)==max1);
f1(i) = f(pos);
max2 = max(wv2(:,i));
pos
= find(wv2(:,i)==max2);
f2(i) = f(pos)+f(pc);
end
figure
plot(t,f1,t,f2)
grid on
title('GAFICA SKEKETON DE FRECUENCIAS')
xlabel('TIEMPO [seg]'), ylabel('FRECUENCIA [Hz]')
% CREACION DE ARCHIVO DE SALIDA
outtable = [t' f1' f2'];
save('outfile.txt', 'outtable', '-ASCII')
Figura Ocho. Grfica del anlisis por Wavelet en frecuencia y tiempo del sistema de 2 GDL.
Figura Nueve. Grfica en planta del anlisis por Wavelet en frecuencia y tiempo del sistema de 2 GDL
Figura Diez. Grfica Skeketon del anlisis por Wavelet en frecuencia y tiempo del sistema de 2 GDL
Se debe tener en cuenta que la rutina en MATLAB genera un archivo de salida outfile.txt que contiene los
valores de tiempo y skeleton de frecuencias.