Matlab Matrices Matriz como tabla de nmeros notas4
Matlab Matrices
Matriz como tabla de números >> notas=[4. 5, 5. 6; 5. 3, 6. 2; 3. 7, 4. 9] notas = 4. 5000 5. 6000 5. 3000 6. 2000 3. 7000 4. 9000 >> v=size(notas) %devuelve vector v= 3 2 >> filas=v(1) % n° de filas en primer elemento (de índice 1) filas = 3 >> cols=v(2) % n° de filas en 2° elemento (de índice 2) cols = 2 >> [filas, cols]=size(notas); %resultado en vector de 2 elementos
Promedios por filas >> notas(1, 3)=(notas(1, 1)+notas(1, 2))/2 %M(n°fila, n°columna) notas = 4. 5000 5. 6000 5. 0500 5. 3000 6. 2000 0 3. 7000 4. 9000 0 >> notas(1, 3)=mean(notas(1, 1: 2)); %M(n°fila, n°col inicial: n°col final) >> notas(2, 3)=mean(notas(2, 1: 2)); %promedio fila 2 >> notas(3, 3)=mean(notas(3, 1: 2)) %promedio fila 3 notas = 4. 5000 5. 6000 5. 0500 5. 3000 6. 2000 5. 7500 3. 7000 4. 9000 4. 3000
Promedios por columnas >> notas(4, 1)=mean(notas(1: 3, 1)) % M(i 1: i 2, j) notas = 4. 5000 5. 6000 5. 0500 5. 3000 6. 2000 5. 7500 3. 7000 4. 9000 4. 3000 4. 5000 0 0 >> notas(4, 2)=mean(notas(1: 3, 2)); % promedio columna 2 >> notas(4, 3)=mean(notas(1: 3, 3)) % promedio columna 3 notas = 4. 5000 5. 6000 5. 0500 5. 3000 6. 2000 5. 7500 3. 7000 4. 9000 4. 3000 4. 5000 5. 5667 5. 0333
Estadígrafos por columnas >> notas(5, 3)=median(notas(1: 3, 3)) ; >> notas(6, 3)=mode(notas(1: 3, 3)) ; >> notas(7, 3)=max(notas(1: 3, 3)) ; >> notas(8, 3)=min(notas(1: 3, 3)) ;
Producto de vectores >> a = [1, 2, 3, 4]; >> b = [5; 6; 7; 8]; >> producto=a*b % suma de productos entre elementos producto = 70 >> c=b‘ % traspuesto (convierte columna a fila) c= 5 6 7 8 >> producto=sum(a. *c) producto = 70
Producto de Matrices >> A A= 1 2 3 4 5 6 >> B B= 1 4 2 5 3 6 >> C=A*B % cada C(i, j)=sum(A(i, : ). * B(: , J)’) suma de fila i por columna j C= 14 32 32 77
Matrices Cuadradas >> A=[1 2; 3 4]; >> B=inv(A) %matriz inversa B= -2. 0000 1. 5000 -0. 5000 >> C=A*B C= 1. 0000 0. 0000 1. 0000 >> I=eye(2, 2) %matriz identidad I= 1 0 0 1 >> AA=A^2 %AA=A*A potencia AA = 7 10 15 22 >> A 1=A*I % I es neutro en producto A 1 = 1 2 3 4
Matriz Inversa %matriz de 2 x=[ nº nº ; nº nº ]; %determinante d=det(x) %d=x(1, 1)*x(2, 2) – x(1, 2)*x(2, 1); %matriz inversa=1/d * [x(2, 2), –x(1, 2); -x(2, 1), x(1, 1)]; %matriz de 3 x=[ nº nº n°; n° n° n°; n° nº nº ]; %determinante M 1=[x(2, 2) x(2, 3); x(3, 2) x(3, 3)]; M 2=[x(2, 1) x(2, 3); x(3, 1) x(3, 3)]; M 3=[x(2, 1) x(2, 2); x(3, 1) x(3, 2)]; d=det(x) %d=x(1, 1)*det(M 1) – x(1, 2)*det(M 2) + x(1, 3)*det(M 3); %matriz inversa=1/d * [x(2, 2)*x(3, 3)-x(2, 3)*x(3, 2), x(1, 3)*x(3, 2)-x(1, 2)*x(3, 3), x(1, 2)*x(2, 3)-x(1, 3)*x(2, 2); x(2, 3)*x(3, 1)-x(2, 1)*x(3, 3), x(1, 1)*x(3, 3)-x(1, 3)*x(3, 1), x(1, 3)*x(2, 1)-x(1, 1)*x(2, 3); x(2, 1)*x(3, 2)-x(2, 2)*x(3, 1), x(1, 2)*x(3, 1)-x(1, 1)*x(3, 2), x(1, 1)*x(2, 2)-x(1, 2)*x(2, 1)];
Sistema Ecuaciones Lineales a 11 x 1 + a 12 x 2 +. . . + a 1 nxn = b 1. . . an 1 x 1 + an 2 x 2 +. . . + annxn = bn Ejemplo 2 x + y – 2 z = 10 3 x + 2 y +2 z = 1 5 x +4 y + 3 z = 4
Solución Algebraica a 11 x 1 + a 12 x 2 +. . . + a 1 nxn = b 1. . . an 1 x 1 + an 2 x 2 +. . . + annxn = bn El sistema corresponde a multiplicar la matriz A (con los coeficientes a ij) por el vector x (con las incógnitas xi):
Solución Algebraica Ax=b multiplicando cada lado de la igualdad por la inversa de A A-1 A x = A-1 b I x = A-1 b
Solución en Matlab >> A=[2 1 -2 ; 3 2 2 ; 5 4 3] A= 2 1 -2 3 2 2 5 4 3 >> b=[10 ; 1; 4] b= 10 1 4 >> x=inv(A)*b x= 1. 0000 2. 0000 -3. 0000 >> x=A^-1*b %o x=Ab usando operador x= 1. 0000 2. 0000 -3. 0000
- Slides: 13