RESOLUCIN DE SISTEMAS DE ECUACIONES MTODO LU Diremos que una matriz invertible A admite una factorizacin triangular o factorizacin LU si puede expresarse como el producto de una matriz triangular L cuyos elementos diagonales son todos iguales a 1 por una matriz triangular U, es decir A = LU (1) o escrito de otra manera _ _ _ _ _ a 11 a 12 a 13 a 21 a 22 a 23 a 31 a 32 a 33 _ _ _ _ _ = _ _ _ _ _ 1 0 0 m 21 1 0 m 31 m 32 1 _ _ _ _ _ _ _ _ _ _ u 11 u 12 u 13 0 u 22 u 23 0 0 u 33 _ _ _ _ _ Supongamos que la matriz de coecientes a de un sistema Ax = b admite una factorizacin triangular, entonces la solucin del sistema es AX = B (2) LUX = B (3) Por denicin: UX = Y (4) _ _ _ LY = B UX = Y 1 ALGORITMO EN MATLAB function x=metodolu(A,b) [n1 n2]=size(A); while n1~=n2 clc fprintf(El sistema no tiene soluciones\n) A=input(Ingresar la matriz A=); [n1 n2]=size(A); end [m]=length(b); while n1~=m clc fprint(Sistema NO Coherente\n) b=input(Ingresar la matriz b=); [m]=length(b); end clc [L U]=lu_(A); disp(Matriz L) L disp(Matriz U) U y=sis_tinferior(L,b); x=sistem_Tsuperior(U,y); end 2 ALGORITMO PARA ENCONTRAR LAS MATRICES L Y U function [L U]=lu_(A) % descomposicion LU sin pivotacion % a: matriz cuadrada [n m]=size(A); if n~=m error(Matriz no cuadrada.); end for j=1:n-1 if A(j,j)==0 error(Pivote nulo.); end for i=(j+1):n factor=A(i,j)/A(j,j); A(i,j)=factor; for k=j+1:n A(i,k)=A(i,k)-factor*A(j,k); end end end L=tril(A,-1)+eye(n); U=triu(A); end ALGORITMO PARA RESOLVER LA EXPRESIN LY=B, MATRIZ INFERIOR function y=sis_tinferior(A,B) [n1 n2]=size(A); y(1)=B(1)/A(1,1); for j=2:n1 y(j)=(B(j)-A(j,j-1:-1:1)*y(j-1:-1:1))/A(j,j); end end ALGORITMO PARA RESOLVER LA EXPRESIN UX=Y, MATRIZ SUPERIOR function x=sistem_Tsuperior(A,B) [n1 n2]=size(A); x(n1)=B(n1)/A(n1,n1); for j=(n1-1):-1:1 x(j)=(B(j)-A(j,j+1:n1)*x(j+1:n1))/A(j,j); end end 3 EJECUCIN DEL PROGRAMA En la pantalla principal de MatLab ingresamos el valor de la matriz A y el vector b. >> A=[1 2 4 1;2 8 6 4;3 10 8 8;4 12 10 6] A = 1 2 4 1 2 8 6 4 3 10 8 8 4 12 10 6 >> b =[ 21 52 79 82] b = 21 52 79 82 Llamamos a la funcin que ejecutar el sistema de ecuaciones y posteriormente obtendremos los resultados. >> x=metodolu(A,b) Matriz L L = 1 0 0 0 2 1 0 0 3 1 1 0 4 1 2 1 Matriz U U = 1 2 4 1 0 4 -2 2 0 0 -2 3 0 0 0 -6 x = 1 2 3 4 4 EJEMPLO >> A=[4 2 8 6;1 5 3 9;9 4 6 2;2 7 4 19] A = 4 2 8 6 1 5 3 9 9 4 6 2 2 7 4 19 >> b=[12 6 4 38] b = 12 6 4 38 >>x=metodolu(A,b) Matriz L L = 1.0000 0 0 0 0.2500 1.0000 0 0 2.2500 -0.1111 1.0000 0 0.5000 1.3333 0.1121 1.0000 Matriz U U = 4.0000 2.0000 8.0000 6.0000 0 4.5000 1.0000 7.5000 0 0 -11.8889 -10.6667 0 0 0 7.1963 x = 3.4286 -5.9844 -1.9013 4.2442 5