1 / 24

MATLAB Indledning II

MATLAB Indledning II. Anders P. Ravn Institut for Datalogi Aalborg Universitet Forår 2005. Hvor er matricen ?. Skiverne skal pakkes i pakker af ca. samme vægt. Hvad er vægten af de næste skiver?. Hvor er matricen ?. Skivevægt (gram) for Fisk1:

azura
Download Presentation

MATLAB Indledning II

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MATLAB Indledning II Anders P. Ravn Institut for Datalogi Aalborg Universitet Forår 2005

  2. Hvor er matricen ? Skiverne skal pakkes i pakker af ca. samme vægt. Hvad er vægten af de næste skiver?

  3. Hvor er matricen ? Skivevægt (gram) for Fisk1: 6 9 13 16 22 24 26 27 27 28 28 28 27 29 31 29 29 32 26 27 30 28 30 28 27 27 25 25 23 23 22 20 25 18 16 15 13 11 Skivevægt (gram) for Fisk2: 3 5 7 6 12 13 11 11 14 14 16 19 23 27 28 29 27 28 31 29 35 32 33 26 26 32 30 28 29 26 35 21 28 21 21 26 7 21 31 31 26 21 16 11 8 11 4 5 3 7 10

  4. Hvor er Matricen ? Et kulpartikel brænder: - Nogle dele er dækket af en askeflage - Andre dele er glød Hvordan udvikler det sig ?

  5. En model function Pnext = step(P,f) % Simulering af forbrænding: emne % er matrix P % med glød = 1 % aske = 0

  6. Delmatricer A = 1 2 3 4 5 6 7 8 9 » A(2:3,1:2) 4 5 7 8 » A(2,2) 5 » A(1,:) 1 2 3 » A(1:2:3,1:2:3) 1 3 7 9 » A(pi,pi) Warning: Subscript indices must be integer values. 9 • A(2:3,1:2) • A(2,2) • A(1,:) • A(1:2:3,1:2:3) • A(pi,pi)

  7. Hvor er matricen ?

  8. Billedbehandling » Udsnit = B(101:104, 301:304, :) Rød 188 183 176 182 198 182 172 172 188 195 173 159 185 188 169 156 Grøn 183 168 162 172 190 172 169 167 179 185 172 158 179 179 166 151 Blå 179 163 159 171 187 163 162 163 174 176 167 153 167 170 157 147

  9. Transponering » D = [1 2 3 4; 5 6 7 8] D = 1 2 3 4 5 6 7 8 » D' 1 5 2 6 3 7 4 8 » A' 1 4 7 2 5 8 3 6 9 Transponering af A A’ Ombytter rækker og søjler

  10. Specielle Matricer » zeros(2,3) 0 0 0 0 0 0 » eye(2,3) 1 0 0 0 1 0 » ones(2,3) 1 1 1 1 1 1 » A = [] » size(A) 0 0 » rand(2,3) 0.9501 0.6068 0.8913 0.2311 0.4860 0.7621 • Nulmatrix • Enhedsmatrix • Etmatrix • Tom matrix • Tilfældige tal • … • … • Se help elmat

  11. Bygning af Matricer a = 1 2 3 » A = [a ; a] 1 2 3 1 2 3 » B = [A , [4 ;4]] 1 2 3 4 1 2 3 4 » C = [A ; a] 1 2 3 1 2 3 1 2 3 » D = [A, a] ??? All matrices on a row in the bracketed expression must have the same number of rows. » D = [A, a'] ??? All matrices on a row in the bracketed expression must have the same number of rows. » D = [C, a'] 1 2 3 1 1 2 3 2 1 2 3 3

  12. Hvor er Matricen ?

  13. Kinematik p = [x , y]’ w1 = [a,b] ‘ A = [ cos(theta) sin(theta) ; -sin(theta) cos(theta) ] wl GLOBAL = (p + A * w1)’

  14. Hvordan bruges det ? p = [x , y] w1 = [a,b] -- lokalt A = [ cos(theta) sin(theta) -sin(theta) cos(theta) ] wl GLOBAL = (p’ + A * w1’)’

  15. Matrix-Division » X = A/B X = 0.6250 0.1250 0.1250 0.6250 » X*B 1.0000 2.0000 2.0000 1.0000 X = A / B betyder at X * B = A Y = A \ B betyder at A * Y = B » Y = 1.6667 -0.3333 -0.3333 1.6667 » A*Y 1 3 3 1 \ “op i”

  16. Hvordan bruges det ? p = [x , y] w1 = [a,b] -- lokalt A = [ cos(theta) sin(theta) -sin(theta) cos(theta) ] wl GLOBAL = (p’ + A * w1’)’ w1‘ = A \ (wl GLOBAL‘ – p’)

  17. Et eksempel q =[q1,q2] p =[p1,p2] Hvad er ligningen for linjen ? y = ax + b – find a og b [p2 ; q2] = [p1 1 ; q1 1] * [a ; b] [p1 1; q1 1] \ [p2 ; q2] = [a ; b]

  18. En løsning [p1 1; q1 1] \ [p2 q 2]’ = [a b]’ » p = [0 0]; q = [1 1]; » A = [p(1) 1; q(1) 1]; a = [p(2) q(2)]; » x = A\a' x = 1 0 findlinje.m » p = [1 1]; q = [3,4]; » findlinje x = 1.5000 -0.5000 » p = [1 1]; q = p; findlinje Warning: Matrix is singular to working precision. x = Inf Inf

  19. Overbestemthed r =[r1,r2] q =[q1,q2] p =[p1,p2] Find den bedste løsning ! y = ax + b [p2; q2; r2] = [p1 1 ; q1 1; r1 1] * [a ; b]

  20. Bedste løsning [p1 1; q1 1; r1 1] \ [p2; q2; r2] = [a ;b] » p = [0 0]; q = [1 1]; r = [2 1] » A = [p(1) 1; q(1) 1; r(1) 1]; a = [p(2) q(2) r(2)]; » x = A\a' x = 0.5000 0.1667

  21. Polynomier [an an-1 an-2 … a1 a0] * [xn xn-1 xn-2 … x1 ]’ » roots([1 -3 3 -1]) ans = 1.0000 1.0000 + 0.0000i 1.0000 - 0.0000i » roots([1 -2 1]) ans = 1 1 » roots([1 -4 6 -4 1]) ans = 1.0001 1.0000 + 0.0001i 1.0000 - 0.0001i 0.9999

  22. Undersøgelse » p2 = [1 -2 1]; » p3 = [1 -3 3 -1]; » p4 = [1 -4 6 -4 1]; » x = 0.6:0.05:1.4; » plot(x,polyval(p2,x), x, polyval(p3,x), x,polyval(p4,x), x,polyval([0],x) )

  23. Andre Operationer » A^2 » A*A 5 4 5 4 4 5 4 5 » hilb(2) 1.0000 0.5000 0.5000 0.3333 » A * hilb(2) == hilb(2) *A 1 0 0 1 » A * hilb(2) 2.0000 1.1667 2.5000 1.3333 » hilb(2) * A 2.0000 2.5000 1.1667 1.3333

  24. Næste gang … Programmer: FOR … , IF …

More Related