least square method
DESCRIPTION
Least Square Method. Curve Fitting. Linear Least Square Method. ตัว. ในกรณีที่มีค่าพารามิเตอร์. จำนวน. Example 1 on page 362. % Linear1.m k =[141 138 119 115]'; T = [390 500 1000 1500]'; X = [T,[1 1 1 1]']; y = k; p =inv(X'*X)*X'*y. Non Linear System of Equation. = Jacobian Matrix. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/1.jpg)
Least Square Method
Curve Fitting
![Page 2: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/2.jpg)
21 mxmy Linear Least Square Method
nnn Rmxmy 21
22121
221
2 222 nnnnnnn Rxmmymyxmxmy
N
nn
N
nnnnnnn Rxmmymyxmxmy
1
2
12121
221
2 222
02221 1
21
21
1
1
2
N
n
N
nn
N
nnnn
N
nn
xmyxxmm
R
022211
22
1
2
N
nn
N
nn
N
nn
xyNmm
R
![Page 3: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/3.jpg)
2
11
2
1111
N
nn
N
n
N
nn
N
nn
N
nnn
xxN
yxyxNm
n
2
11
2
111 1
2
2
N
nn
N
n
N
nn
N
nnn
N
n
N
nn
xxN
xyxyxm
n
n
![Page 4: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/4.jpg)
M
iiimxy
1
21 mxmy
m M ในกรณี�ที่��มี�ค่�าพารามี�เตอร� จำ�านวน ต�ว
εmXy
mXymXyεε
TTN
nnR
1
2
N
nn
N
nnnnnnn Rxmmymyxmxmy
1
2
12121
221
2 222
![Page 5: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/5.jpg)
02 T1
2
XmXym
N
n
R
0 mXyX T
0 mXXyX TT
yXXXm TT 1
![Page 6: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/6.jpg)
Example 1 on page 362
21 pTpk
T]115 119 138 141[k
T]1500 1000 500 390[T
2
1
21
]1 [ p
pT
pTpk
y'XX'Xp 1
% Linear1.mk =[141 138 119 115]';T = [390 500 1000 1500]';X = [T,[1 1 1 1]'];y = k;p =inv(X'*X)*X'*y
![Page 7: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/7.jpg)
Non Linear System of Equation
0,...,,
0,...,,
0,...,,
21
212
211
nn
n
n
xxxf
xxxf
xxxf
0... ,,1,
2
,,21,2
1
,,11,1,1,
n
ikinin
ikii
ikiiikik
x
fxx
x
fxx
x
fxxff
![Page 8: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/8.jpg)
n
ikin
iki
iki
n
ikin
iki
ikiik
x
fx
x
fx
x
fx
x
fx
x
fx
x
fxf
,
1,2
,1,2
1
,1,1
,,
2
,,2
1
,,1,
...
...
sym
...
...
...
,
2
,
1
,
,2
2
,2
2
,2
,1
2
,1
1
,1
n
ininin
n
iii
n
iii
x
f
x
f
x
f
x
f
x
f
x
fx
f
x
f
x
f
Z
= Jacobian Matrix
![Page 9: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/9.jpg)
inii
Ti
iniiT
i
iniiT
i
fff
xxx
xxx
,,2,1
1,1,21,11
,,2,1
...
...
...
F
x
x
1 iiT
i xZxZF
iT
ii xZFZx
11
![Page 10: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/10.jpg)
Example
03
1
3
112
27
10
9
2
3
52
03
2
3
11
27
8
9
2
3
42
2
212121
2
212121
xxxxxx
xxxxxx
2
,2
1
,2
2
,1
1
,1
x
f
x
f
x
f
x
f
ii
ii
Z
![Page 11: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/11.jpg)
2121212
,2
2121211
,2
2121212
,1
2121211
,1
3
1
3
11
3
22
27
20
27
10
9
2
3
52
3
1
3
11
3
22
9
4
27
10
9
2
3
52
3
2
3
11
3
4
27
16
27
8
9
2
3
42
3
2
3
11
3
2
9
4
27
8
9
2
3
42
xxxxxxx
f
xxxxxxx
f
xxxxxxx
f
xxxxxxx
f
i
i
i
i
![Page 12: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/12.jpg)
clear; c1 = 1; c2 = 1; %First Guess NONLINEAR1.m
for i=1:10
X = [c1;c2];
f1 = 2*(4/3-2/9*c1-8/27*c2)*(c1+c2)+(1-1/3*c1-2/3*c2)^2;
f2 = 2*(5/3-2/9*c1-10/27*c2)*(c1+2*c2)+(1+1/3*c1+1/3*c2)^2;
F = [f1;f2];
df1c1 = 2*(4/3-2/9*c1-8/27*c2)- 4/9*(c1+c2)- 2/3*(1-1/3*c1-2/3*c2);
df1c2 = 2*(4/3-2/9*c1-8/27*c2)- 16/27*(c1+c2)- 4/3*(1-1/3*c1-2/3*c2);
df2c1 = 2*(5/3-2/9*c1-10/27*c2)- 4/9*(c1+2*c2)+ 2/3*(1+1/3*c1+1/3*c2);
df2c2 = 4*(5/3-2/9*c1-10/27*c2)- 20/27*(c1+2*c2)+ 2/3*(1+1/3*c1+1/3*c2);
Z = [df1c1,df1c2;df2c1,df2c2];
W = -F+Z*X;
Xnew = inv(Z)*W;
c1 =Xnew(1);c2= Xnew(2);
fprintf(' %g %g %g\n',i,c1,c2);
end
![Page 13: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/13.jpg)
Non Linear Least Square εmXy
02 T1
2
m
XmXy
m
N
n
R
0
T
mXym
X
Numerically
mXymXyεε
TTN
nnR
1
2
![Page 14: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/14.jpg)
other
*mm
m
*mX*mXy
Expand {y} by Taylor
m
*mXH
*mXyHHH*mm T1T
*mmH*mX y
*mmHH*mXH TT y
![Page 15: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/15.jpg)
Example : Stress Relaxation
54321 expexp at-aat-ay = a
Time Force
.000001, 3.083900
.016670, 1.647600
.033330, 1.176900
.050000, .935450
.066670, .784570
.083330, .681970
.100000, .609550
![Page 16: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/16.jpg)
Example : Stress Relaxation
54321 expexp at-aat-ay = a
2
,2
1
,2
2
,1
1
,1
x
f
x
f
x
f
x
f
ii
ii
Z
54321 a
f
a
f
a
f
a
f
a
f iiiiiH
*mXyHHH*mm T1T
m
*mXH
![Page 17: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/17.jpg)
54321 expexp at-aat-ay = a
54321 a
f
a
f
a
f
a
f
a
f iiiiiH
t-aa
fi2
1
exp
1 5
= a
fi
t-ata= a
fi21
2
exp
t-a=a
fi4
3
exp
t-ata= a
fi43
4
exp
Stess.m
![Page 18: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/18.jpg)
% Parameters Estimation% Using Stress Relaxation Data% Five parametersclear; clc; clf;Data= ...[ 1, .000001, 3.083900 2, .016670, 1.647600 3, .033330, 1.176900 4, .050000, .935450 5, .066670, .784570 6, .083330, .681970 7, .100000, .609550 8, .116670, .555230 9, .133330, .506950 10, .150000, .470740 20, .316670, .289690 30, .483330, .223300 40, .650000, .181050 50, .816670, .156910 60, .983330, .138810 70, 1.150000, .126740 80, 1.316700, .114670 90, 1.483300, .108630 100, 1.650000, .102600 110, 1.816700, .090530 120, 1.983300, .084490 130, 2.150000, .084490 140, 2.316700, .078460 150, 2.483300, .078460 160, 2.650000, .078460 170, 2.816700, .072420 180, 2.983300, .072420 190, 3.150000, .066390 200, 3.316700, .066390 220, 3.650000, .060350 240, 3.983300, .060350 260, 4.316700, .054320 280, 4.650000, .060350 300, 4.983300, .048280 350, 5.816700, .048280 400, 6.650000, .048280 500, 8.316700, .042250 600, 9.983300, .036210];
![Page 19: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/19.jpg)
t = Data(:,2);y = Data(:,3)*1000/224.8089;y = y/y(1);plot(t,y,'ro');legend('Data','Fit');xlabel('Time');ylabel('Force');title ('Non Linear Regression');axis([min(t) round(max(t)) 0 1]);hold on;Plothandle = plot(t,y,'-','EraseMode','xor');
![Page 20: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/20.jpg)
a =[10;10;10;1;1]; % First Guess of three parametersda =1; i=0;while da>1e-20 ym = a(1)*exp(-a(2)*t)+a(3)*exp(-a(4)*t)+a(5); dyda1 = exp(-a(2)*t); dyda2 = -a(1)*t.*exp(-a(2)*t); dyda3 = exp(-a(4)*t); dyda4 = -a(3)*t.*exp(-a(4)*t); dyda5 = 1+zeros(size(t));
Jacob = [dyda1,dyda2,dyda3,dyda4,dyda5]; anew = a +0.1*inv(Jacob'*Jacob)*Jacob'*(y-ym); da = norm(anew-a); a = anew; i=i+1; fprintf( 'Iter = %g Par = %g %g %g %g%g\n',i,a(1),a(2),a(3),a(4),a(5)); set (Plothandle,'ydata',ym); drawnow; hold off;end
![Page 21: Least Square Method](https://reader035.vdocuments.net/reader035/viewer/2022062301/56813b55550346895da44582/html5/thumbnails/21.jpg)
ybar = mean(y); SSr = sum((ym-ybar).^2);Syy = sum((y-ybar).^2); R2 = SSr/Syy;fprintf( ' Parameter = %g %g %g %g %g\n',a(1),a(2),a(3),a(4),a(5));fprintf( ' R_square = %g \n',R2);
1 Research Method Lecture 11-3 (Ch15) Instrumental Variables Estimation and Two Stage Least Square ©
1 Research Method Lecture 11-2 (Ch15) Instrumental Variables Estimation and Two Stage Least Square ©