This method belongs to the LU factoring system. From matrix A, there are two matrices L and U, in this method the matrix L is lower triangular and the matrix U is upper triangular, but the two matrices L and U have the same values in the diagonal. However, if A is symmetric and positive definite, the factors can be chosen such that U is the transpose of L.
The factorization can be calculated directly through the following formulas
For the elements of the main diagonal, and:
For the rest of the elements. Where uij are the elements of the matrix U.
Pseudocode.
Input A, b
n= # de filas de A
L=eye(n);
U=eye(n);
for k=1:n
suma=0;
for p=1:k-1
suma=suma+L(k,p)*U(p,k);
end
L(k,k)= sqrt(A(k,k)-suma);
U(k,k) = L(k,k);
for i=k+1:n
suma=0;
for p=1:k-1
suma=suma+L(i,p)*U(p,k);
end
L(i,k)=(A(i,k)-suma)/L(k,k);
end
for j= k+1:n
suma=0;
for p=1:k-1
suma=suma+L(k,p)*U(p,j);
end
U(k,j)=(A(k,j)-suma)/L(k,k);
end
end
for i=1:n
suma=0;
for p=1:i-1
suma=suma+L(i,p)*d(p,1);
end
d(i,1)=(b(i,1)-suma)/L(i,i);
end
for i=n:-1:1
suma=0;
for p=i+1:n
suma=suma+U(i,p)*X(p,1);
end
X(i,1)=(d(i,1)-suma)/U(i,i);
end
Code.
clc
A=input('ingrese la matriz: ');
b=input('ingrese la matriz de términos independientes: ');
n=size(A,1);
L=eye(n);
U=eye(n);
for k=1:n
suma=0;
for p=1:k-1
suma=suma+L(k,p)*U(p,k);
end
L(k,k)= sqrt(A(k,k)-suma);
U(k,k) = L(k,k);
for i=k+1:n
suma=0;
for p=1:k-1
suma=suma+L(i,p)*U(p,k);
end
L(i,k)=(A(i,k)-suma)/L(k,k);
end
for j= k+1:n
suma=0;
for p=1:k-1
suma=suma+L(k,p)*U(p,j);
end
U(k,j)=(A(k,j)-suma)/L(k,k);
end
end
disp('U=')
disp(U)
disp('L=')
disp(L)
disp('L*U=')
disp(L*U)
for i=1:n
suma=0;
for p=1:i-1
suma=suma+L(i,p)*d(p,1);
end
d(i,1)=(b(i,1)-suma)/L(i,i);
end
disp('d=');
disp(d);
for i=n:-1:1
suma=0;
for p=i+1:n
suma=suma+U(i,p)*X(p,1);
end
X(i,1)=(d(i,1)-suma)/U(i,i);
end
disp('La solucion es: ')
disp(X)
B=A*X