Title: MATLAB ??????? ?????????
1MATLAB ????????????????
- ???
- jang_at_cs.nthu.edu.tw
- http//www.cs.nthu.edu.tw/jang
- ????? ????????
27-1????????
- n ????????
- MATLAB ?,? n1 ?????? p(x)
- Ex. p 1,2,3,1 ?????????
3?????? (I)
- ??????,??????????
- ????, ?
- ??????
- ??7-1polyPlus.m
p1 1,0,1,1 p2 0,1,-1,2 p1 p2 p1 - p2
4?????? (II)
ans 1 1 0 3 ans 1
-1 2 -1
- ?? p1 ? p2 ??????,?? MATLAB ??????????
5?????? (I)
- ??????,?? conv ? deconv ????
- ????? ? ???
- ??7-2conv01.m
- ????????,?
p1 1, 0, 1, 1 p2 0, 1, -1, 2 p3
conv(p1, p2)
p3 0 1 -1 3 0 1 2
6?????? (II)
- ?? ?? ??????
- ??7-3deconv01.m
- ?? ?? ,???? ,??
p1 1, 0, 1, 1 p2 1, -1, 2 q, r
deconv(p1, p2)
q 1 1 r 0 0 0 -1
7????????
?? ??
p1 p2 ??? ? ??
p1 - p2 ??? ? ??
conv(p1, p2) ??? ? ???
q, r deconv(p1, p2) ??? ?? ,????? ,???
87-2 ???????????????
- ???????,?? polyval ??
- ??7-4polyval01.m
p 1 2 1 x 00.13 y polyval(p,
x) plot(x, y, '-o')
9???????-1
- x ? y ???? 31 ???,y(i) ???
- ? x x(i) ????
10???????-2
- ??p(A),A???,??polyvalm??
- ??7-5polyvalm01.m
- ??? B A2 2A 1 ??
p 1 2 1 A 1 2 3 4 B polyvalm(p, A)
B 10 14 21 31
11??????? (I)
- ?????,?? roots ????
- ??? ??
- ??7-6roots01.m
p 1, 3, 1, 5, -1 ??? r roots(p)
??????
r -3.2051 0.0082 1.2862i
0.0082 - 1.2862i 0.1886
12??????? (II)
- ??????,?????
- ??7-7roots02.m
p 1, 3, 1, 5, -1 ??? r roots(p)
?????? polyval(p, r) ?????????
ans 1.0e-012 0.1465 -0.0135
0.0271i -0.0135 - 0.0271i 0.0002
13??
- fzero??
- ?????????
- ???????
- ?????
- Roots??
- ????????
- ????????
- ?????????????(Companion Matrix),??????????
14??????
- ???????,????polyder
- ??7-8polyder01.m
- ?? ???????
p 1 3 3 1 q polyder(p)
q 3 6 3
15?????? (I)
- MATLAB 6.x ?????? polyint ??
- ??7-9polyint02.m
- ?? ????
p 4 3 2 1 k 8 ???????? q polyint(p,
k) ???????
q 1 1 1 1 8
16?????? (II)
- MATLAB 5.x ???????????
- ?????????
- ??7-10polyint01.m
p 4 3 2 1 t length(p)-11 k 8
???????? q p./t, k ???????
q 1 1 1 1 8
17?????????????
?? ??
q polyval(p, x) ?? p(x) ???
q polyvalm(a, A) ?? p(A),A ?????
q polyder(p) q(x) ? p(x) ????
q p./length(p)-11, k q(x) ? p(x) ???,?? k ??????
q polyint(p, k) q(x) ? p(x) ???,?? k ??????(??????? MATLAB 6.x ??????)
18????????
- ????? A,???????
- ?? poly ?????????
- ??7-11poly01.m
- ???? A ??????
A 1 3 4 2 4 1 1 6 2 p poly(A)
p 1.0000 -7.0000 -2.0000 -25.0000
19??????
- ??????????? A ????
- ??7-12poly02.m
A 1 3 4 2 4 1 1 6 2 p poly(A)
???????? r roots(p) ???????,????? det(A-r(1)
eye(3)) det(A-r(2)eye(3)) det(A-r(3)eye(3))
ans -9.5707e-014 ans -2.5292e-014 -
1.5899e-015i ans -2.5292e-014 1.5899e-015i
20??
- ????????? ,???? A
????????(Eigenvalues)??? - ??eig??????? A ?????????
217-4 ??????
- ?? residue ????????????
- A(s) ? B(s) ????,? B(s) ???
- ?? ?????
- , ,, ? ??(? ???)
- , ,, ???
- ?????
22????????? (I)
- ?? ???????
- ??7-13residue01.m
b 3 8 a 1 5 6 r, p, k residue(b, a)
23????????? (II)
r 1.0000 2.0000 p -3.0000
-2.0000 k
24??
- ????????????????????(Transfer Function)???
- ? ?????????,???????????,???????(Impulse
Response)?
25?????????
- residue ??????????????
- ??7-14residue02.m
- ????????????
r 1 2 p -3 -2 k b2, a2
residue(r, p, k)
b2 3 8 a2 1 5 6
267-5?????
- ????(Curve Fitting)
- ??????????
- ??????????????????
- ????????????,????????????(Polynomial Fitting)
- polyfit ???????????
27??????? (I)
- ?????1790?1990(10???)??
- ??7-15plotCensus.m
load census.mat plot(cdate, pop, 'o')
xlabel('??') ylabel('??(????)')
28??????? (II)
29??????? (III)
- ???????? 2002 ?????,?? polyfit ?????????????
- ??7-16polyfit01.m
load census.mat plot(cdate, pop, 'o') p3
polyfit(cdate, pop, 3) cdate2 17902002 pop2
polyval(p3, cdate2) plot(cdate, pop, 'o',
cdate2, pop2, '-') xlabel('??') ylabel('??(????
)') legend('????', '????') popAt2002
polyval(p3, 2002)
30??????? (IV)
- ?????? 2002 ??????? 282.5 ???
population 282.5332
31??????? (I)
- ????????????,????(Extrapolation)?????????
- ??7-17polyfit02.m
load census.mat cdate2 min(cdate)(max(cdate)30
) curve zeros(7, length(cdate2)) for i
17 curve(i,) polyval(polyfit(cdate,pop,i),
cdate2) end plot(cdate, pop,'o', cdate2,
curve) legend('????', 'order1',
'order2','order3', 'order4', 'order5',
'order6', 'order7') xlabel('??') ylabel('??(??
??)')
32??????? (II)
- ????,?????????
- ????????????
- ????????(Noise)?????,????????????
33???????????
- ?????,??? MATLAB ????
- ?????????
- ?????????????
- ?????????,?????????????????????