Capitulo 2 Matlab
Capitulo 2 Matlab
FACULTAD DE INGENIERIA
QUIMICA
MATLAB
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 =
>> linspace(1,2,5)
ans =
>> 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 =
>> rand(6)
ans =
>> rand(3)
ans =
>> rand(2,5)
ans =
>> 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 =
ans =
0.7394 -0.1941
1.7119 -2.1384
>> randn(5)
ans =
>> randn(3)
ans =
>> 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
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 =
>> inv(b)
ans =
>> inv(c)
ans =
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
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
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=
>> diag(x)
ans =
9.00 0 0
0 5.00 0
0 0 23.00
>> w=[8 5 6]
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=
>> b=[2,9,3,1;5,3,6,2;,8,9,6,1;8,6,2,3]
b=
>> 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
>> 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
>> tril(b)
ans =
2.00 0 0 0
5.00 3.00 0 0
>> tril(c)
ans =
6.00 0 0 0
5.00 6.00 0 0
.
>> triu(a)
ans =
0 0 3.00 1.00
0 0 0 2.00
>> triu(b)
ans =
0 0 6.00 1.00
0 0 0 3.00
>> triu(c)
ans =
0 0 1.00 3.00
0 0 0 9.00
>> sum(a)
ans =
>> sum(b)
ans =
>> sum(c)
ans =
>> prod(a)
ans =
>> prod(b)
ans =
>> prod(c)
ans =
>> min(a)
ans =
>> min(b)
ans =
>> min(c)
ans =
>> max(a)
ans =
ans =
>> max(c)
ans =
>> det(a)
ans =
72.00
>> det(b)
ans =
657.00
>> det(c)
ans =
367.00
>> 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
Columns 5 through 7
>> cumsum(l)
ans =
Columns 1 through 4
Columns 5 through 7
>> cumsum(m)
ans =
Columns 1 through 4
Columns 5 through 7
>> 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
Columns 5 through 7
>> cumprod(m)
ans =
Columns 1 through 4
Columns 5 through 7
ans =
Columns 1 through 4
Columns 5 through 7
>> cumprod(k)
ans =
Columns 1 through 4
Columns 5 through 7
>> [v,p]=sort(l)
v=
Columns 1 through 4
1.00 3.00 3.00 5.00
Columns 5 through 7
p=
Columns 1 through 4
Columns 5 through 7
>> [v,p]=sort(m)
v=
Columns 1 through 4
Columns 5 through 7
Columns 1 through 4
Columns 5 through 7
>> [v,p]=sort(k)
v=
Columns 1 through 4
Columns 5 through 7
p=
Columns 1 through 4
3.00 1.00 5.00 7.00
Columns 5 through 7
>> length(m)
ans =
7.00
>> length(k)
ans =
7.00
>> length(l)
ans =
7.00
>> vector1=2:2:24
vector1 =
Columns 1 through 4
Columns 5 through 8
Columns 9 through 12
>> vector2=3:4:19
vector2 =
3 7 11 15 19
>> vector3=5:2.3:19
vector3 =
Columns 1 through 6
Column 7
18.8000
>> vector4=linspace(2,19,8)
vector4 =
Columns 1 through 6
Columns 7 through 8
16.5714 19.0000
>> vector5=linspace(2,18,10)
vector5 =
Columns 1 through 6
Columns 7 through 10
>> 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=
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
Columns 7 through 12
>> 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
>> c=[6 8 1 0 3]
c=
6 8 1 0 3
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
Column 11
15
>> conv(b,c)
ans =
>> conv(c,d)
ans =
>> conv(d,e)
ans =
48 -62 -35 0 7 55 14 -3 -4 -5
>> conv(a,e)
ans =
Columns 1 through 10
Column 11
-3
>> [c,r]=deconv(a,b)
c=
0.3333
r=
>> [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=
>> [c,r]=deconv(d,e)
c=
r=
8 -1 -3 -4 -5
>> [c,r]=deconv(a,e)
c=
0.3333
r=
>> 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 =
>> polyder(a,b)
ans =
>> polyder(b,c)
ans =
10 0 2 0 -3
>> polyder(c,d)
ans =
>> polyder(d,e)
ans =
>> polyder(a,e)
ans =