Matlab indledning ii
Sponsored Links
This presentation is the property of its rightful owner.
1 / 24

MATLAB Indledning II PowerPoint PPT Presentation


  • 78 Views
  • Uploaded on
  • Presentation posted in: General

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:

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


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:

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


Hvor er Matricen ?

Et kulpartikel brænder:

- Nogle dele er dækket af en askeflage

- Andre dele er glød

Hvordan udvikler det sig ?


En model

function Pnext = step(P,f)

% Simulering af forbrænding: emne

% er matrix P

% med glød = 1

% aske = 0


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)


Hvor er matricen ?


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


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


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


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


Hvor er Matricen ?


Kinematik

p = [x , y]’

w1 = [a,b] ‘

A = [ cos(theta) sin(theta) ;

-sin(theta) cos(theta) ]

wl GLOBAL = (p + A * w1)’


Hvordan bruges det ?

p = [x , y]

w1 = [a,b] -- lokalt

A = [ cos(theta) sin(theta)

-sin(theta) cos(theta) ]

wl GLOBAL = (p’ + A * w1’)’


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”


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’)


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]


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


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]


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


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


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) )


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


Næste gang …

Programmer:

FOR … , IF …


  • Login