Matlab Matrices
Matriz como tabla de números >> notas=[4.5,5.6; 5.3, 6.2; 3.7,4.9] notas = >> 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 = >> 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 =
Promedios por columnas >> notas(4,1)=mean(notas(1:3,1)) % M(i1:i2,j) notas = >> notas(4,2)=mean(notas(1:3,2)); % promedio columna 2 >> notas(4,3)=mean(notas(1:3,3)) % promedio columna 3 notas =
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 = >> producto=sum(a.*c) producto = 70
Producto de Matrices >> A A = >> B B = >> C=A*B % cada C(i,j)=sum(A(i,:).* B(:,J)’) suma de fila i por columna j C =
Matrices Cuadradas >> A=[1 2; 3 4]; >> B=inv(A) %matriz inversa B = >> C=A*B C = >> I=eye(2,2) %matriz identidad >> A1=A*I % I es neutro en producto I = A1 = >> AA=A^2 %AA=A*A potencia AA =
Matriz Inversa %matriz de 2 x 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 inversa=1/d * [x(2,2), –x(1,2); -x(2,1), x(1,1)]; %matriz de 3 x 3 x=[ nº nº n°; n° n° n°; n° nº nº ]; %determinante M1=[x(2,2) x(2,3); x(3,2) x(3,3)]; M2=[x(2,1) x(2,3); x(3,1) x(3,3)]; M3=[x(2,1) x(2,2); x(3,1) x(3,2)]; d=det(x) %d=x(1,1)*det(M1) – x(1,2)*det(M2) + x(1,3)*det(M3); %matriz inversa 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 a 1n x n = b 1... a n1 x 1 + a n2 x a nn x n = b n Ejemplo 2x + y – 2z = 10 3x + 2y +2z = 1 5x +4y + 3z = 4
Solución Algebraica a 11 x 1 + a 12 x a 1n x n = b 1... a n1 x 1 + a n2 x a nn x n = b n El sistema corresponde a multiplicar la matriz A (con los coeficientes a ij ) por el vector x (con las incógnitas x i ):
Solución Algebraica A x = b multiplicando cada lado de la igualdad por la inversa de A A -1 A x = A -1 b I x = A -1 b x = A -1 b
Solución en Matlab >> A=[ ; ; 5 4 3] A = >> b=[10 ; 1; 4] b = >> x=inv(A)*b x = >> x=A^-1*b %o x=A\b usando operador \ x =