Beruflich Dokumente
Kultur Dokumente
Practica No 1
Mátricula: 1735609
Carrera: IME
Salón: CTL7
En esta práctica de Laboratorio de Ingeniería de Control se ven los distintos comandos básicos de Matlab,
para hacer operaciones con variables, funciones, y arreglos de vectores, así como también guardar,
importar y conocer un poco el Work Space y la Command WIndow. Se mencionarán los comandos
utilizados.
Comandos y Expresiones
Los comandos se pueden teclear directamente en Matlab como las operaciones básicas de una
multiplicación, división, resta y suma, usando los símbolos: * / * - . Por ejemplo:
4/2;
ans=
Variables
Las variables tienen que llamarse antes de hacer cualquier operación en ella, por ejemplo:
a= 4; b=5;
SUMA= a + b;
SUMA= 9
Nos eliminan y muestran las variables con las que estamos trabajando.
Funciones
Las funciones son muchas en Matlab, pero considerando las báicas y las utilizadas en la práctica son:
Log(), Log10(), abs(), exp(), sqrt(), etc, que serían las funciones de logaritmo, logaritmo base 10, valor
absoluto, función exponencial, raíz cuadrada, etc.
Vectores
En Matlab se trabaja también con vectores y estos se denotan escribiendo las filas separados con espacios
o comas (,), y columnas utilizando el punto y coma (;).
De aquí salen otras funciones como la Transpuesta (‘), inversa inv( ), identidad eye( ), etc.
Y se pueden ccrear Vectores con valores de cierto rango como de 0 a 5 en intervalos de 0.1 o 0.01, etc.
Gráficos Simples
Se pueden hacer gráficos sencillos con las funciones Seno y Coseno, incluso combinando vectores como
anteriormente lo mencionamos, se pueden graficar estos valores seleccionando un rango con intervalos, y
aplicándoles una función senoidal o cosenoidal podemos obtener una gráfica.
Matrices
Igual que un vector, se pueden elaborar matrices de x tamaño y se pueden hacer operaciones como, suma
algebraica, multiplicación, matrices inversas y transpuestas, también matrices identidad.
>> A=[1,0;-2,4;3,-1]
A=
1 0
-2 4
3 -1
>> B=[3,-4;5,1]
B=
3 -4
5 1
>> C=[2,-3,0;4,5,-1;6,1,-1]
C=
2 -3 0
4 5 -1
6 1 -1
>> E=(inv(C)*A)' - (inv(B')*A'*C')
E=
>> D= [1;-4;2]
D=
-4
>> F= 100*((C'.*C)./(D*D'*C))'*det(inv(B))
F=
-8.6957 -6.5217 0
0 0.5435 1.0870
G=
>> frpintf('y = Sen(wt) - wt Cos(wt)\n\n Para un tiempo t de 0 a 5 con incrementos de 0.01 y w=2pi')
>> fprintf('y = Sen(wt) - wt Cos(wt)\n\n Para un tiempo t de 0 a 5 con incrementos de 0.01 y w=2pi')
y = Sen(wt) - wt Cos(wt)
Para un tiempo t de 0 a 5 con incrementos de 0.01 y w=2pi>>
>> t=(0:0.01:5);
>> w= 2*pi;
y=
Columns 1 through 12
0 0.0001 0.0007 0.0022 0.0053 0.0102 0.0176 0.0278 0.0413 0.0584 0.0795 0.1049
Columns 13 through 24
0.1349 0.1698 0.2098 0.2550 0.3057 0.3617 0.4233 0.4903 0.5627 0.6404 0.7233
0.8110
Columns 25 through 36
0.9033 1.0000 1.1006 1.2047 1.3119 1.4217 1.5335 1.6468 1.7609 1.8752 1.9890
2.1016
Columns 37 through 4
2.2123 2.3204 2.4250 2.5255 2.6211 2.7109 2.7943 2.8704 2.9386 2.9981 3.0482
3.0882
Columns 49 through 60
3.1175 3.1355 3.1416 3.1353 3.1162 3.0837 3.0376 2.9776 2.9034 2.8148 2.7117
2.5942
Columns 61 through 72
2.4621 2.3158 2.1552 1.9807 1.7927 1.5915 1.3777 1.1517 0.9143 0.6662 0.4081
0.1408
Columns 73 through 84
-0.1346 -0.4172 -0.7061 -1.0000 -1.2979 -1.5985 -1.9006 -2.2030 -2.5043 -2.8033 -3.0985 -
3.3887
Columns 85 through 96
-3.6724 -3.9482 -4.2149 -4.4710 -4.7152 -4.9462 -5.1627 -5.3634 -5.5473 -5.7130 -5.8596 -
5.9859
-6.0910 -6.1741 -6.2343 -6.2709 -6.2832 -6.2707 -6.2330 -6.1697 -6.0805 -5.9654 -5.8244 -
5.6574
-5.4647 -5.2467 -5.0037 -4.7364 -4.4453 -4.1313 -3.7952 -3.4381 -3.0610 -2.6652 -2.2520 -
1.8227
-1.3789 -0.9221 -0.4541 0.0235 0.5088 1.0000 1.4951 1.9922 2.4893 2.9843 3.4752
3.9598
4.4362 4.9021 5.3557 5.7948 6.2174 6.6215 7.0053 7.3668 7.7043 8.0160 8.3003
8.5556
8.7805 8.9737 9.1339 9.2601 9.3511 9.4063 9.4248 9.4061 9.3498 9.2556 9.1234
8.9533
8.7453 8.5000 8.2177 7.8992 7.5453 7.1570 6.7354 6.2819 5.7978 5.2847 4.7444
4.1787
3.5896 2.9792 2.3497 1.7034 1.0428 0.3702 -0.3116 -1.0000 -1.6924 -2.3860 -3.0780 -
3.7656
-4.4460 -5.1163 -5.7738 -6.4156 -7.0391 -7.6414 -8.2199 -8.7721 -9.2954 -9.7874 -10.2459 -
10.6685
-12.1663 -11.9411 -11.6663 -11.3426 -10.9707 -10.5518 -10.0869 -9.5777 -9.0256 -8.4325 -
7.8003 -7.1313
-6.4277 -5.6922 -4.9272 -4.1357 -3.3205 -2.4847 -1.6314 -0.7640 0.1143 1.0000 1.8897
2.7797
3.6666 4.5469 5.4168 6.2728 7.1114 7.9291 8.7224 9.4880 10.2224 10.9227 11.5855
12.2081
12.7875 13.3210 13.8063 14.2408 14.6225 14.9494 15.2197 15.4320 15.5848 15.6770
15.7080 15.6769
15.5834 15.4275 15.2092 14.9289 14.5873 14.1852 13.7237 13.2043 12.6285 11.9983
11.3157 10.5830
9.8028 8.9779 8.1111 7.2056 6.2648 5.2922 4.2913 3.2660 2.2201 1.1577 0.0830 -
1.0000
-2.0869 -3.1735 -4.2553 -5.3281 -6.3876 -7.4293 -8.4490 -9.4426 -10.4058 -11.3345 -12.2250 -
13.0732
-13.8757 -14.6287 -15.3291 -15.9736 -16.5593 -17.0834 -17.5435 -17.9372 -18.2626 -18.5179 -
18.7016 -18.8124
-18.8496 -18.8123 -18.7003 -18.5135 -18.2521 -17.9168 -17.5083 -17.0278 -16.4767 -15.8568 -
15.1701 -14.4189
-0.2802 1.0000 2.2842 3.5672 4.8440 6.1094 7.3584 8.5858 9.7867 10.9560 12.0891
13.1811
14.2275 15.2238 16.1658 17.0494 17.8707 18.6261 19.3123 19.9260 20.4645 20.9251
21.3055 21.6038
21.8184 21.9478 21.9911 21.9477 21.8171 21.5994 21.2950 20.9046 20.4292 19.8704
19.2297 18.5094
17.7117 16.8396 15.8959 14.8842 13.8079 12.6710 11.4778 10.2326 8.9401 7.6052 6.2329
4.8285
3.3975 1.9452 0.4775 -1.0000 -2.4814 -3.9610 -5.4327 -6.8907 -8.3292 -9.7423 -11.1243 -
12.469
-13.7725 -15.0277 -16.2300 -17.3744 -18.4559 -19.4700 -20.4123 -21.2786 -22.0653 -22.7686 -
23.3854 -23.9129
-24.3484 -24.6898 -24.9352 -25.0832 -25.1327 -25.0831 -24.9339 -24.6853 -24.3379 -23.8924 -
23.3502 -22.7130
-21.9827 -21.1619 -20.2533 -19.2602 -18.1861 -17.0347 -15.8104 -14.5176 -13.1611 -11.7461 -
10.2777 -8.7617
-7.2037 -5.6098 -3.9861 -2.3390 -0.6748 1.0000 2.6787 4.3547 6.0214 7.6720 9.3000
10.8988
26.3064 26.9007 27.3913 27.7757 28.0520 28.2186 28.2743 28.2185 28.0507 27.7713
27.3808 26.8803
26.2712 25.5556 24.7357 23.8144 22.7950 21.6809 20.4762 19.1853 17.8129 16.3642
14.8445 13.2595
11.6153 9.9182 8.1745 6.3911 4.5748 2.7327 0.8720 -1.0000 -2.8760 -4.7485 -6.6100 -
8.4533
-10.2708 -12.0553 -13.7995 -15.4965 -17.1392 -18.7209 -20.2351 -21.6755 -23.0361 -24.3113 -
25.4955 -26.5837
>> plot(t,y)
>> gride
>> grid
>> ylabel('f(t)')
>>
>> fprintf('y= e^(-at)Sen(wt) + e^(-at)Cos(wt)\n\n Para un tiempo t de 0 a 4 con incrementos de 001 y a=2,
w= 2pi\n\n')
y= e^(-at)Sen(wt) + e^(-at)Cos(wt)
>> w2=2*pi;
>> t2=(0:0.01:4);
> wt2=w2.*t2;
>>
y2 =
Columns 1 through 11
1.0000 1.0398 1.0736 1.1016 1.1237 1.1402 1.1511 1.1568 1.1573 1.1528 1.1436
Columns 12 through 22
1.1299 1.1119 1.0899 1.0641 1.0348 1.0022 0.9666 0.9283 0.8876 0.8447 0.7998
Columns 23 through 33
0.7533 0.7054 0.6564 0.6065 0.5560 0.5051 0.4541 0.4031 0.3524 0.3021 0.2526
Columns 34 through 44
0.2039 0.1563 0.1099 0.0648 0.0212 -0.0208 -0.0610 -0.0994 -0.1359 -0.1703 -0.2027
Columns 45 through 55
-0.2330 -0.2610 -0.2869 -0.3105 -0.3319 -0.3510 -0.3679 -0.3825 -0.3950 -0.4052 -0.4134
Columns 56 through 66
-0.4194 -0.4235 -0.4256 -0.4257 -0.4241 -0.4207 -0.4157 -0.4090 -0.4009 -0.3915 -0.3807
Columns 67 through 77
-0.3687 -0.3556 -0.3415 -0.3265 -0.3107 -0.2942 -0.2771 -0.2595 -0.2415 -0.2231 -0.2045
Columns 78 through 88
-0.1858 -0.1670 -0.1483 -0.1296 -0.1112 -0.0929 -0.0750 -0.0575 -0.0404 -0.0238 -0.0078
Columns 89 through 99
0.0076 0.0224 0.0366 0.0500 0.0627 0.0746 0.0857 0.0960 0.1055 0.1142 0.1221
Columns 100 through 110
0.1291 0.1353 0.1407 0.1453 0.1491 0.1521 0.1543 0.1558 0.1566 0.1566 0.1560
0.1548 0.1529 0.1505 0.1475 0.1440 0.1400 0.1356 0.1308 0.1256 0.1201 0.1143
0.1082 0.1019 0.0955 0.0888 0.0821 0.0752 0.0684 0.0614 0.0545 0.0477 0.0409
0.0342 0.0276 0.0212 0.0149 0.0088 0.0029 -0.0028 -0.0083 -0.0135 -0.0184 -0.0231
-0.0274 -0.0315 -0.0353 -0.0388 -0.0420 -0.0449 -0.0475 -0.0498 -0.0518 -0.0535 -0.0548
-0.0559 -0.0568 -0.0573 -0.0576 -0.0576 -0.0574 -0.0569 -0.0563 -0.0554 -0.0543 -0.0530
-0.0515 -0.0499 -0.0481 -0.0462 -0.0442 -0.0421 -0.0398 -0.0375 -0.0351 -0.0327 -0.0302
Columns 177 through 187
-0.0277 -0.0251 -0.0226 -0.0201 -0.0175 -0.0150 -0.0126 -0.0102 -0.0078 -0.0055 -0.0032
-0.0011 0.0010 0.0030 0.0049 0.0068 0.0085 0.0101 0.0116 0.0130 0.0143 0.0155
0.0165 0.0175 0.0183 0.0190 0.0197 0.0202 0.0206 0.0209 0.0211 0.0212 0.0212
0.0211 0.0209 0.0207 0.0204 0.0200 0.0195 0.0190 0.0184 0.0177 0.0170 0.0163
0.0155 0.0146 0.0138 0.0129 0.0120 0.0111 0.0102 0.0093 0.0083 0.0074 0.0065
0.0055 0.0046 0.0037 0.0029 0.0020 0.0012 0.0004 -0.0004 -0.0011 -0.0018 -0.0025
-0.0031 -0.0037 -0.0043 -0.0048 -0.0053 -0.0057 -0.0061 -0.0064 -0.0067 -0.0070 -0.0072
-0.0074 -0.0076 -0.0077 -0.0078 -0.0078 -0.0078 -0.0078 -0.0077 -0.0076 -0.0075 -0.0073
-0.0072 -0.0070 -0.0068 -0.0065 -0.0063 -0.0060 -0.0057 -0.0054 -0.0051 -0.0048 -0.0044
-0.0041 -0.0037 -0.0034 -0.0031 -0.0027 -0.0024 -0.0020 -0.0017 -0.0014 -0.0011 -0.0007
-0.0004 -0.0001 0.0001 0.0004 0.0007 0.0009 0.0011 0.0014 0.0016 0.0018 0.0019
0.0021 0.0022 0.0024 0.0025 0.0026 0.0027 0.0027 0.0028 0.0028 0.0029 0.0029
0.0029 0.0029 0.0028 0.0028 0.0028 0.0027 0.0026 0.0026 0.0025 0.0024 0.0023
0.0009 0.0007 0.0006 0.0005 0.0004 0.0003 0.0002 0.0001 -0.0001 -0.0002 -0.0002
-0.0003 -0.0004 -0.0005 -0.0006 -0.0006 -0.0007 -0.0008 -0.0008 -0.0009 -0.0009 -0.0009
-0.0010 -0.0010 -0.0010 -0.0010 -0.0010 -0.0011 -0.0011 -0.0011 -0.0010 -0.0010 -0.0010
-0.0010 -0.0010 -0.0009 -0.0009 -0.0009 -0.0008 -0.0008 -0.0008 -0.0007 -0.0007 -0.0006
-0.0006 -0.0006 -0.0005 -0.0005 -0.0004 -0.0004 -0.0003 -0.0003 -0.0002 -0.0002 -0.0001
-0.0001 -0.0001 -0.0000 0.0000 0.0001 0.0001 0.0001 0.0002 0.0002 0.0002 0.0002
>> plot=(t2,y2)
plot=(t2,y2)
>> plot(t2,y2)
>> grid
>> ylabel('f(t)')
>>
>> t3=(0:0.01:3);
>> w3=2*pi;
>> wt3=w3*t3;
y3 =
Columns 1 through 12
0 -0.0023 -0.0019 0.0031 0.0134 0.0296 0.0520 0.0808 0.1164 0.1590 0.2089
0.2663
Columns 13 through 24
0.3314 0.4044 0.4855 0.5749 0.6729 0.7796 0.8952 1.0199 1.1538 1.2971 1.4500
1.6126
Columns 25 through 36
1.7850 1.9674 2.1598 2.3625 2.5753 2.7985 3.0321 3.2762 3.5307 3.7958 4.0714
4.3575
Columns 37 through 48
4.6541 4.9612 5.2787 5.6066 5.9448 6.2932 6.6518 7.0204 7.3988 7.7871 8.1850
8.5923
Columns 49 through 60
9.0090 9.4348 9.8696 10.3132 10.7653 11.2259 11.6947 12.1714 12.6559 13.1480 13.6474
14.1540
Columns 61 through 72
14.6675 15.1878 15.7145 16.2476 16.7868 17.3319 17.8827 18.4391 19.0010 19.5680
20.1401 20.7172
Columns 73 through 84
21.2991 21.8857 22.4769 23.0726 23.6728 24.2773 24.8862 25.4994 26.1168 26.7386
27.3646 27.9950
Columns 85 through 96
28.6298 29.2690 29.9128 30.5612 31.2142 31.8722 32.5351 33.2032 33.8766 34.5555
35.2400 35.9305
36.6270 37.3298 38.0391 38.7553 39.4784 40.2088 40.9468 41.6925 42.4462 43.2083
43.9789 44.7584
45.5470 46.3449 47.1524 47.9698 48.7973 49.6351 50.4835 51.3426 52.2128 53.0941
53.9869 54.8911
55.8071 56.7349 57.6747 58.6266 59.5907 60.5670 61.5557 62.5567 63.5701 64.5959
65.6342 66.6847
67.7476 68.8228 69.9101 71.0094 72.1207 73.2438 74.3785 75.5247 76.6822 77.8508
79.0302 80.2203
81.4207 82.6313 83.8517 85.0817 86.3211 87.5694 88.8264 90.0919 91.3655 92.6468
93.9356 95.2316
96.5345 97.8439 99.1595 100.4810 101.8082 103.1408 104.4784 105.8209 107.1679 108.5192
109.8746 111.2338
112.5967 113.9630 115.3327 116.7054 118.0812 119.4599 120.8413 122.2255 123.6124 125.0019
126.3940 127.7887
129.1860 130.5861 131.9890 133.3947 134.8034 136.2153 137.6304 139.0489 140.4711 141.8972
143.3273 144.7617
146.2008 147.6447 149.0937 150.5482 152.0085 153.4748 154.9475 156.4271 157.9137 159.4077
160.9096 162.4196
182.9496 184.6090 186.2813 187.9665 189.6649 191.3766 193.1019 194.8407 196.5932 198.3595
200.1396 201.9336
203.7414 205.5630 207.3985 209.2476 211.1104 212.9868 214.8765 216.7794 218.6953 220.6241
222.5655 224.5192
226.4851 228.4628 230.4520 232.4524 234.4637 236.4855 238.5175 240.5594 242.6107 244.6711
246.7401 248.8175
250.9027 252.9955 255.0953 257.2019 259.3148 261.4336 263.5579 265.6875 267.8219 269.9607
272.1037 274.2505
276.4007 278.5542 280.7105 282.8696 285.0311 287.1947 289.3604 291.5279 293.6972 295.8679
298.0402 300.2138
302.3888 304.5652 306.7428 308.9218 311.1022 313.2841 315.4676 317.6529 319.8400 322.0292
324.2207 326.4147
328.6115 330.8113 333.0145 335.2212 337.4320 339.6471 341.8669 344.0917 346.3220 348.5581
350.8005 353.0496
Column 301
355.3058
>> plot(t3,y3)
>> grid
>> ylabel('f(t)')
>>
>> whoes
>> whos
A 3x2 48 double
B 2x2 32 double
C 3x3 72 double
D 3x1 24 double
E 2x3 48 double
F 3x3 72 double
G 3x3 72 double
a 1x1 8 double
w 1x1 8 double
w2 1x1 8 double
w3 1x1 8 double
En este caso como después de la introducción, ya se mencionaron los comandos utilizados y aprendidos.
No es tan complicado ya que al llevar algo básico de programación en c++ se facilita el aprendizaje, pero
de igual forma el usuario puede aprender fácilmente sin tener experiencia alguna en programación. El
único detalle que puede faltar en la práctica para la comprobación de ésta, es el código necesario que,
respalde el resultado de las gráficas. Como primer problema necesito de alguna forma extraer de la
ventana de comandos el código para recuperarlo y en próximas prácticas introducirlo y así tener un mejor
contenido. El programar funciones en Matlab y trabajar con vectores la verdad que agiliza al usuario y
motiva a pensar el mejor arreglo de variables para efectuar la operación: no tener errores ortográficos,
usar el menor número de variables posibles, graficar, etc.