Você está na página 1de 5

Ajustamento

mtodo dos mnimos quadrados


S = d 1 2 +d 2 2 +d 3 2 +.........+d n 2
S = minima
S = (f 1 y 1)2 +(f 2 y 2)2 +( f 3 y 3 )2 +......+(f n y n )2
S (a , b)=(ax 1 +b y 1)2 +( ax 2+ b y 2 )+ .......+(ax n +b y n )2
S
=2(ax 1 +b y 1) x 1+ 2(ax 2 +b y 2) x2 +....+2( ax n+ b y n) x n=0
b
S
=2(ax 1 +b y 1)+2(ax2 +b y 2 )+....+2( ax n+ b y n)=0
b
a( x1 2 + x 2 2 +....+ xnn 2)+ b( x 1+ x2 +....+ x n)=x1 y 1 + x 2 y 2 +.... x n y n
a( x1 + x 2 +....+ xn )+b( 1+1+....+1)= y 1 + y 2 +....+ y n
parablico
f (x)=ax 2+ bx+ c S( a , b , c)mnima

[]

x1 1
x2 1
X= . . ; Y =
. .
. .
xn 1

[]

y1
y2
a
;
C=
b
.
c
.
yn

C=(X t . X ) 1 .( X t . Y )

[]

//-1 = inversa ou \ no matlab

Exemplo 1. Ajuste a reta dos mnimos quadrados pelos pontos


( 1,10 ) , ( 0,9 ) , (1, 7 ) , ( 2,5) , ( 3, 4 ) , ( 4,3) , ( 3, 0 ) , ( 6, 1) .
x = [-1 0 1 2 3 4 3 6]'
y = [10 9 7 5 4 3 0 -1]'
X = [x ones(size(x))]
X=
-1
0
1
2
3
4
3
6

1
1
1
1
1
1
1
1

Y=y
Y=
10
9
7
5
4
3
0
-1
C = (X'*X)\(X'*Y)
C=
-1.6408
8.3169
plot(x,y,'*b'),grid
hold on

t = min(x):0.01:max(x);
f = polyval(C,t);
plot(t,f,'r'),grid

Exemplo 2
x = [-3 0 2 4]'
y = [3 1 1 3]'
plot(x,y,'*b'),grid, hold on

X = [x.^2 x x.^0] = estou transformando num polinmio de grau 2. J que uma parbola.
X=
9 -3
0 0
4 2
16 4

1
1
1
1

C = (X'*X)\(X'*Y)
C=
0.1785
-0.1925
0.8505
t = min(x):0.01:max(x);
f = polyval(C,t);
ento
f(x) = 0.1785x^2-0.1925x + 0.8505
plot(t,f,'r'),grid

Você também pode gostar