0% found this document useful (0 votes)
36 views58 pages

Capitulo 2 Matlab

The document discusses types of predefined matrices in MATLAB such as eye, zeros, ones, rand, and randn. It also covers basic matrix functions like size, det, inv, and operations like transpose and extracting submatrices. Examples are provided to illustrate different matrix types and functions.

Uploaded by

Jair Ricse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views58 pages

Capitulo 2 Matlab

The document discusses types of predefined matrices in MATLAB such as eye, zeros, ones, rand, and randn. It also covers basic matrix functions like size, det, inv, and operations like transpose and extracting submatrices. Examples are provided to illustrate different matrix types and functions.

Uploaded by

Jair Ricse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 58

UNIVERSIDAD NACIONAL

DEL CENTRO DEL PERÚ

FACULTAD DE INGENIERIA
QUIMICA

MATLAB

CATEDRA: LENGUAJE DE PROGRAMACION

CATEDRATICO: HENRY OCHOA

ESTUDIANTE: HURTADO BARRIENTOS JENNIFER LESLY

SEMESTRE: II

SECCIÓN: A

HUANCAYO-2017
TIPOS DE MATRICES PREFINIDAS
>> eye(4)

ans =

1 0 0 0

0 1 0 0

0 0 1 0

0 0 0 1

>> eye(9)

ans =

1 0 0 0 0 0 0 0 0

0 1 0 0 0 0 0 0 0

0 0 1 0 0 0 0 0 0

0 0 0 1 0 0 0 0 0

0 0 0 0 1 0 0 0 0

0 0 0 0 0 1 0 0 0

0 0 0 0 0 0 1 0 0

0 0 0 0 0 0 0 1 0

0 0 0 0 0 0 0 0 1

>> eye(5)

ans =

1 0 0 0 0

0 1 0 0 0
0 0 1 0 0

0 0 0 1 0

0 0 0 0 1

>> zeros(5,6)

ans =

0 0 0 0 0 0

0 0 0 0 0 0

0 0 0 0 0 0

0 0 0 0 0 0

0 0 0 0 0 0

>> zeros(2,6)

ans =

0 0 0 0 0 0

0 0 0 0 0 0

>> zeros(5,4)

ans =

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0
0 0 0 0

>> ones(6)

ans =

1 1 1 1 1 1

1 1 1 1 1 1

1 1 1 1 1 1

1 1 1 1 1 1

1 1 1 1 1 1

1 1 1 1 1 1

>> ones(4)

ans =

1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1

>> ones(3)

ans =

1 1 1

1 1 1

1 1 1
>> linspace(1,6,3)

ans =

1.0000 3.5000 6.0000

>> linspace(1,2,5)

ans =

1.0000 1.2500 1.5000 1.7500 2.0000

>> linspace(3,6,1)

ans =

>> linspace(3,6,2)

ans =

3 6

>> linspace(1,2,5)

ans =
1.0000 1.2500 1.5000 1.7500 2.0000

>> rand(5)

ans =

0.8147 0.0975 0.1576 0.1419 0.6557

0.9058 0.2785 0.9706 0.4218 0.0357

0.1270 0.5469 0.9572 0.9157 0.8491

0.9134 0.9575 0.4854 0.7922 0.9340

0.6324 0.9649 0.8003 0.9595 0.6787

>> rand(6)

ans =

0.7577 0.0318 0.3171 0.7952 0.7547 0.4984

0.7431 0.2769 0.9502 0.1869 0.2760 0.9597

0.3922 0.0462 0.0344 0.4898 0.6797 0.3404

0.6555 0.0971 0.4387 0.4456 0.6551 0.5853

0.1712 0.8235 0.3816 0.6463 0.1626 0.2238

0.7060 0.6948 0.7655 0.7094 0.1190 0.7513

>> rand(3)

ans =

0.2551 0.8909 0.1386

0.5060 0.9593 0.1493


0.6991 0.5472 0.2575

>> rand(2,5)

ans =

0.8407 0.8143 0.9293 0.1966 0.6160

0.2543 0.2435 0.3500 0.2511 0.4733

>> rand(5,2)

ans =

0.3517 0.2858

0.8308 0.7572

0.5853 0.7537

0.5497 0.3804

0.9172 0.5678

>> rand(6,3)

ans =

0.0759 0.5688 0.3112

0.0540 0.4694 0.5285

0.5308 0.0119 0.1656

0.7792 0.3371 0.6020

0.9340 0.1622 0.2630

0.1299 0.7943 0.6541


>> randn(2)

ans =

0.7394 -0.1941

1.7119 -2.1384

>> randn(5)

ans =

-0.8396 1.4367 0.8252 1.0984 -0.8236

1.3546 -1.9609 1.3790 -0.2779 -1.5771

-1.0722 -0.1977 -1.0582 0.7015 0.5080

0.9610 -1.2078 -0.4686 -2.0518 0.2820

0.1240 2.9080 -0.2725 -0.3538 0.0335

>> randn(3)

ans =

-1.3337 -0.2991 -1.7502

1.1275 0.0229 -0.2857

0.3502 -0.2620 -0.8314

>> magic(3)

ans =
8 1 6

3 5 7

4 9 2

>> magic(8)

ans =

64 2 3 61 60 6 7 57

9 55 54 12 13 51 50 16

17 47 46 20 21 43 42 24

40 26 27 37 36 30 31 33

32 34 35 29 28 38 39 25

41 23 22 44 45 19 18 48

49 15 14 52 53 11 10 56

8 58 59 5 4 62 63 1

>> magic(5)

ans =

17 24 1 8 15

23 5 7 14 16

4 6 13 20 22

10 12 19 21 3

11 18 25 2 9

FUNCIONES MATRICIALES ELEMENTALES


>> f=a'

f=

5 6 21 51

4 7 3 6

6 8 4 3

2 9 9 1

>> g=b'

g=

13 5 32 6

65 6 8 7

7 1 4 2

1 7 1 1

>> h=c'

h=

23 6 2 26

65 4 1 45

4 7 5 8

8 9 6 9

>> t=trace(a)
t=

17

>> s=trace(b)

s=

24

>> o=trace(c)

o=

41

>> size(a)

ans =

4 4

>> size(b)

ans =

4 4

>> size(c)
ans =

4 4

>> det(a)

ans =

5912

>> det(b)

ans =

-10418

>> det(c)

ans =

3.3280e+03

>> inv(a)

ans =

0.0189 -0.0311 0.0257 0.0108

-0.3547 0.3774 -0.3117 0.1187

0.4257 -0.2441 0.1582 -0.0781


-0.1152 0.0553 0.0847 -0.0301

>> inv(b)

ans =

0.0070 0.0107 0.0517 -0.1333

0.0253 0.0111 0.0090 -0.1123

-0.1038 -0.1441 -0.1771 1.2894

-0.0119 0.1463 -0.0194 0.0073

>> inv(c)

ans =

-0.0415 0.2665 -0.4126 0.0454

0.0234 -0.1289 0.1680 -0.0039

-0.1316 -1.0454 1.3645 0.2527

0.1196 0.8038 -0.8609 -0.2251

APLICACIÓN DE MATRICES
-Definición de una matriz

>> a=[5,4,6,2;6,7,8,9;21,3,4,9;51,6,3,1]

a=

5 4 6 2

6 7 8 9

21 3 4 9
51 6 3 1

>> b=[13,65,7,1;5,6,1,7;32,8,4,1;6,7,2,1]

b=

13 65 7 1

5 6 1 7

32 8 4 1

6 7 2 1

>> c=[23,65,4,8;6,4,7,9;2,1,5,6;26,45,8,9]

c=

23 65 4 8

6 4 7 9

2 1 5 6

26 45 8 9

>> d=[3,9,7,6;6,2,8,2;9,3,1,2;92,5,4,2]

d=

3 9 7 6

6 2 8 2

9 3 1 2

92 5 4 2
>> e=[2,4,6,8;6,4,8,9;7,5,9,4;2,5,6,1]

e=

2 4 6 8

6 4 8 9

7 5 9 4

2 5 6 1

-Transposición de una matriz


>> f=a'

f=

5 6 21 51

4 7 3 6

6 8 4 3

2 9 9 1

>> g=b'

g=

13 5 32 6

65 6 8 7

7 1 4 2

1 7 1 1

>> h=c'
h=

23 6 2 26

65 4 1 45

4 7 5 8

8 9 6 9

>> a(2,1:3)

ans =

6 7 8

>> a([1,3],[2,4])

ans =

4 2

3 9

>> b([1,3],[2,4])

ans =

65 1

8 1

>> [c(1:2,1:2);c(3:4,3:4)]
ans =

23 65

6 4

5 6

8 9

>> a(2,1:3)'

ans =

>> b([1,3],[2,4])'

ans =

65 8

1 1

>> [c(1:2,1:2);c(3:4,3:4)]'

ans =

23 6 5 8

65 4 6 9

SUBMATRICES
>> a(2,1:3)

ans =

6 7 8

>> a([1,3],[2,4])

ans =

4 2

3 9

>> b([1,3],[2,4])

ans =

65 1

8 1

>> [c(1:2,1:2);c(3:4,3:4)]

ans =

23 65

6 4

5 6

8 9

ASIGNACION DE UNA MATRIZ


>> a(2,3)

ans =

>> a(2,4)

ans =

>> a(1,3)

ans =

>> a(:,2)

ans =

>> b(:,3)
ans =

>> b(:,1)

ans =

13

32

>> a(2,:)

ans =

6 7 8 9

MATRICES ESPECIALES
-Funciones de matrices

>> v=[6 5 3]

v=
6.00 5.00 3.00

>> diag(v)

ans =

6.00 0 0

0 5.00 0

0 0 3.00

>> x=[9 5 23]

x=

9.00 5.00 23.00

>> diag(x)

ans =

9.00 0 0

0 5.00 0

0 0 23.00

>> w=[8 5 6]

w=

8.00 5.00 6.00


>> diag(w)

ans =

8.00 0 0

0 5.00 0

0 0 6.00

>> a=[5,6,3,2;8,5,6,2;5,6,3,1;9,8,3,2]

a=

5.00 6.00 3.00 2.00

8.00 5.00 6.00 2.00

5.00 6.00 3.00 1.00

9.00 8.00 3.00 2.00

>> b=[2,9,3,1;5,3,6,2;,8,9,6,1;8,6,2,3]

b=

2.00 9.00 3.00 1.00

5.00 3.00 6.00 2.00

8.00 9.00 6.00 1.00

8.00 6.00 2.00 3.00

>> c=[6,3,4,7;5,6,2,3;9,6,1,3;6,2,8,9]

c=
6.00 3.00 4.00 7.00

5.00 6.00 2.00 3.00

9.00 6.00 1.00 3.00

6.00 2.00 8.00 9.00

>> diag(a)

ans =

5.00

5.00

3.00

2.00

>> diag(b)

ans =

2.00

3.00

6.00

3.00

>> diag(c)

ans =

6.00
6.00

1.00

9.00

>> diag(diag(a))

ans =

5.00 0 0 0

0 5.00 0 0

0 0 3.00 0

0 0 0 2.00

>> diag(diag(b))

ans =

2.00 0 0 0

0 3.00 0 0

0 0 6.00 0

0 0 0 3.00

>> diag(diag(c))

ans =

6.00 0 0 0

0 6.00 0 0

0 0 1.00 0
0 0 0 9.00

>> tril(a)

ans =

5.00 0 0 0

8.00 5.00 0 0

5.00 6.00 3.00 0

9.00 8.00 3.00 2.00

>> tril(b)

ans =

2.00 0 0 0

5.00 3.00 0 0

8.00 9.00 6.00 0

8.00 6.00 2.00 3.00

>> tril(c)

ans =

6.00 0 0 0

5.00 6.00 0 0

9.00 6.00 1.00 0

6.00 2.00 8.00 9.00

.
>> triu(a)

ans =

5.00 6.00 3.00 2.00

0 5.00 6.00 2.00

0 0 3.00 1.00

0 0 0 2.00

>> triu(b)

ans =

2.00 9.00 3.00 1.00

0 3.00 6.00 2.00

0 0 6.00 1.00

0 0 0 3.00

>> triu(c)

ans =

6.00 3.00 4.00 7.00

0 6.00 2.00 3.00

0 0 1.00 3.00

0 0 0 9.00

>> sum(a)
ans =

27.00 25.00 15.00 7.00

>> sum(b)

ans =

23.00 27.00 17.00 7.00

>> sum(c)

ans =

26.00 17.00 15.00 22.00

>> prod(a)

ans =

1800.00 1440.00 162.00 8.00

>> prod(b)

ans =

640.00 1458.00 216.00 6.00

>> prod(c)
ans =

1620.00 216.00 64.00 567.00

>> min(a)

ans =

5.00 5.00 3.00 1.00

>> min(b)

ans =

2.00 3.00 2.00 1.00

>> min(c)

ans =

5.00 2.00 1.00 3.00

>> max(a)

ans =

9.00 8.00 6.00 2.00


>> max(b)

ans =

8.00 9.00 6.00 3.00

>> max(c)

ans =

9.00 6.00 8.00 9.00

>> det(a)

ans =

72.00

>> det(b)

ans =

657.00

>> det(c)

ans =
367.00

FUNCIONES QUE ACTUAN SOBRE VECTORES

>> k=[5 8 3 12 5 18 5];

>> l=[3 6 5 8 8 1 3];

>> m=[9 23 25 63 18 5 6];

>> min(k)

ans =

3.00

>> min(l)

ans =

1.00

>> min(m)

ans =

5.00

>> max(k)

ans =
18.00

>> max(l)

ans =

8.00

>> max(m)

ans =

63.00

>> sum(l)

ans =

34.00

>> sum(k)

ans =

56.00

>> sum(m)

ans =
149.00

>> cumsum(k)

ans =

Columns 1 through 4

5.00 13.00 16.00 28.00

Columns 5 through 7

33.00 51.00 56.00

>> cumsum(l)

ans =

Columns 1 through 4

3.00 9.00 14.00 22.00

Columns 5 through 7

30.00 31.00 34.00

>> cumsum(m)
ans =

Columns 1 through 4

9.00 32.00 57.00 120.00

Columns 5 through 7

138.00 143.00 149.00

>> mean(m)

ans =

21.29

>> mean(l)

ans =

4.86

>> mean(k)

ans =

8.00

>> std(m)
ans =

20.07

>> std(k)

ans =

5.29

>> std(l)

ans =

2.67

>> prod(m)

ans =

176053500.00

>> prod(l)

ans =

17280.00

>> prod(k)
ans =

648000.00

>> cumprod(m)

ans =

Columns 1 through 4

9.00 207.00 5175.00 326025.00

Columns 5 through 7

5868450.00 29342250.00 176053500.00

>> cumprod(m)

ans =

Columns 1 through 4

9.00 207.00 5175.00 326025.00

Columns 5 through 7

5868450.00 29342250.00 176053500.00


>> cumprod(l)

ans =

Columns 1 through 4

3.00 18.00 90.00 720.00

Columns 5 through 7

5760.00 5760.00 17280.00

>> cumprod(k)

ans =

Columns 1 through 4

5.00 40.00 120.00 1440.00

Columns 5 through 7

7200.00 129600.00 648000.00

>> [v,p]=sort(l)

v=

Columns 1 through 4
1.00 3.00 3.00 5.00

Columns 5 through 7

6.00 8.00 8.00

p=

Columns 1 through 4

6.00 1.00 7.00 3.00

Columns 5 through 7

2.00 4.00 5.00

>> [v,p]=sort(m)

v=

Columns 1 through 4

5.00 6.00 9.00 18.00

Columns 5 through 7

23.00 25.00 63.00


p=

Columns 1 through 4

6.00 7.00 1.00 5.00

Columns 5 through 7

2.00 3.00 4.00

>> [v,p]=sort(k)

v=

Columns 1 through 4

3.00 5.00 5.00 5.00

Columns 5 through 7

8.00 12.00 18.00

p=

Columns 1 through 4
3.00 1.00 5.00 7.00

Columns 5 through 7

2.00 4.00 6.00

>> length(m)

ans =

7.00

>> length(k)

ans =

7.00

>> length(l)

ans =

7.00

ASIGNACION DE UN VECTOR DE COORDENADAS

>> vector1=2:2:24

vector1 =
Columns 1 through 4

2.00 4.00 6.00 8.00

Columns 5 through 8

10.00 12.00 14.00 16.00

Columns 9 through 12

18.00 20.00 22.00 24.00

>> format short

>> vector2=3:4:19

vector2 =

3 7 11 15 19

>> vector3=5:2.3:19

vector3 =

Columns 1 through 6

5.0000 7.3000 9.6000 11.9000 14.2000 16.5000

Column 7
18.8000

>> vector4=linspace(2,19,8)

vector4 =

Columns 1 through 6

2.0000 4.4286 6.8571 9.2857 11.7143 14.1429

Columns 7 through 8

16.5714 19.0000

>> vector5=linspace(2,18,10)

vector5 =

Columns 1 through 6

2.0000 3.7778 5.5556 7.3333 9.1111 10.8889

Columns 7 through 10

12.6667 14.4444 16.2222 18.0000

>> vector5=linspace(1,8,4)

vector5 =
1.0000 3.3333 5.6667 8.0000

>> d=[65,5,9;4,89,63;25,4,1]

d=

65 5 9

4 89 63

25 4 1

>> e=[5,96,32,4;125,26,54,1;85,65,4,7]

e=

5 96 32 4

125 26 54 1

85 65 4 7

>> f=[5,7,5,21]

f=

5 7 5 21

>> d(3,2)

ans =
4

>> e(3,4)

ans =

>> f(1,3)

ans =

>> d(3,2)=85

d=

65 5 9
4 89 63
25 85 1

>> e(3,4)=542

e=

5 96 32 4
125 26 54 1
85 65 4 542
>> f(1,3)=63214

f=

5 7 63214 21

>> e=[5,96,32,4;125,26,54,1;85,65,4,7]

e=

5 96 32 4
125 26 54 1
85 65 4 7

>> d=[65,5,9;4,89,63;25,4,1]

d=

65 5 9
4 89 63
25 4 1

>> d(:,1)=[1;2;3]

d=

1 5 9
2 89 63
3 4 1
>> e(2,:)=[8541 9658 4785 8954]

e=

5 96 32 4
8541 9658 4785 8954
85 65 4 7

>> f(1,:)=[854 958 785 954]

f=

854 958 785 954

SUBVECTORES

>> vector1=6:3:24

vector1 =

6 9 12 15 18 21 24

>> vector1(2:5)

ans =

9 12 15 18
>> vector2=9:6:84
vector2 =

Columns 1 through 10

9 15 21 27 33 39 45 51 57 63

Columns 11 through 13

69 75 81

>> vector2=7:13

vector2 =

7 8 9 10 11 12 13
>> vector=0.5:0.5:6

vector =

Columns 1 through 6

0.5000 1.0000 1.5000 2.0000 2.5000 3.0000

Columns 7 through 12

3.5000 4.0000 4.5000 5.0000 5.5000 6.0000

>> vector(10:11)

ans =
5.0000 5.5000
POLINOMIOS
>> a=[2 8 0 0 6 -3]

a=

2 8 0 0 6 -3

>> b=[6 0 2 0 -9 -5]

b=

6 0 2 0 -9 -5

>> c=[6 8 1 0 3]

c=

6 8 1 0 3

>> d=[8 -1 -3 -4 -5]

d=

8 -1 -3 -4 -5

>> e=[6 -7 -3 0 0 1]

e=
6 -7 -3 0 0 1

>> roots(a)

ans =

-3.9449 + 0.0000i
-1.1472 + 0.0000i
0.3246 + 0.8018i
0.3246 - 0.8018i
0.4430 + 0.0000i

>> roots(b)

ans =

1.1546 + 0.0000i
0.1094 + 1.2111i
0.1094 - 1.2111i
-0.6867 + 0.1286i
-0.6867 - 0.1286i

>> roots(c)

ans =

-1.0215 + 0.3953i
-1.0215 - 0.3953i
0.3548 + 0.5393i
0.3548 - 0.5393i

>> roots(d)

ans =

1.1808 + 0.0000i
-0.7960 + 0.0000i
-0.1299 + 0.8050i
-0.1299 - 0.8050i

>> roots(e)

ans =

1.4710 + 0.0000i
0.5832 + 0.0000i
-0.6362 + 0.0000i
-0.1256 + 0.5381i
-0.1256 - 0.5381i
>> polyval(a,5)

ans =

11277

>> polyval(b,24)

ans =
47803171

>> polyval(c,2.5)

ans =

368.6250

>> polyval(d,8.3)

ans =

3.7150e+04

>> polyval(e,1.3)

ans =

-3.3061

>> conv(a,b)

ans =

Columns 1 through 10

12 48 4 16 18 -100 -28 -6 -54 -3

Column 11
15

>> conv(b,c)

ans =

36 48 18 16 -34 -102 -43 -5 -27 -15

>> conv(c,d)

ans =

48 58 -18 -49 -41 -47 -14 -12 -15

>> conv(d,e)

ans =

48 -62 -35 0 7 55 14 -3 -4 -5

>> conv(a,e)

ans =

Columns 1 through 10

12 34 -62 -24 36 -58 11 9 0 6

Column 11
-3

>> [c,r]=deconv(a,b)

c=

0.3333

r=

0 8.0000 -0.6667 0 9.0000 -1.3333

>> [c,r]=deconv(b,c)

c=

18 0 6 0 -27 -15

r=

0 0 0 0 0 0

>> [c,r]=deconv(c,d)

c=

2.2500 0.2813
r=

0 0 13.0313 9.8438 -14.6250 -13.5938

>> [c,r]=deconv(d,e)

c=

r=

8 -1 -3 -4 -5

>> [c,r]=deconv(a,e)

c=

0.3333

r=

0 10.3333 1.0000 0 6.0000 -3.3333

>> residue(a,b)

ans =
0.2476 + 0.2569i
0.2476 - 0.2569i
0.4253 + 0.0000i
0.2065 - 0.9709i
0.2065 + 0.9709i

>> residue(b,c)

ans =

[]

>> residue(b,c)

ans =

[]

>> residue(c,d)

ans =

0.0089 + 0.0000i
0.0052 + 0.0152i
0.0052 - 0.0152i
-0.0193 + 0.0000i

>> residue(d,e)
ans =

0.5303 + 0.0000i
-0.2476 + 0.0000i
1.4824 + 0.0000i
-0.2159 + 0.4343i
-0.2159 - 0.4343i

>> residue(a,e)

ans =

1.7906 + 0.0000i
-0.6736 + 0.0000i
-0.3031 + 0.0000i
0.4542 + 0.5535i
0.4542 - 0.5535i

>> polyder(a)

ans =

10 32 0 0 6

>> polyder(b)

ans =

30 0 6 0 -9
>> polyder(c)

ans =

>> polyder(d)

ans =

32 -3 -6 -4

>> polyder(e)

ans =

30 -28 -9 0 0

>> polyder(polyder(a))

ans =

40 96 0 0

>> polyder(polyder(b))

ans =

120 0 12 0
>> polyder(polyder(c))

ans =

>> polyder(polyder(d))

ans =

96 -6 -6

>> polyder(polyder(e))

ans =

120 -84 -18 0

>> polyder(a,b)

ans =

120 432 32 112 108 -500 -112 -18 -108 -3

>> polyder(b,c)

ans =

10 0 2 0 -3
>> polyder(c,d)

ans =

10.6667 -1.0000 -2.0000 -1.3333

>> polyder(d,e)

ans =

432 -496 -245 0 35 220 42 -6 -4

>> polyder(a,e)

ans =

120 306 -496 -168 216 -290 44 27 0 6

You might also like