mathajax

Solve System of Linear Equations by LU Decompose

One of the application of LU matrix decomposition is solving system of linear equations.

Ax = b

  • A - coefficient matrix
  • b - non-homogeneous vector
  • x - unknown vector (solution vector)

system of linear equation
The square matrix (coefficient matrix) A decomposed into LU (lower triangular and upper triangular) matrix by elementary-row-operations.

A = LU

the solution vector X of system found by forward and back substitution.
  • y = forward-substitute L and b
  • X = back-substitute U and y

The two or more system of equations have same coefficient matrix A but have different non-homogeneous vectors (b1 ,b2,..), the solutions vectors (x1,x2,..) obtained by once applying LU decomposition over matrix A.
System 1
  Ax = b1
System 2
  Ax = b2
  • LU = LU-decompose(A)
  • System 1
    1. y = forward-substitute (L , b1)
    2. x = back-substitute (U,y)
  • System 2
    1. y = forward-substitute (L , b2)
    2. x= back-substitute (U,y)


Algorithm Steps for Solving System of Linear Equations by LU Decompose

       Input : a square matrix, A,
        non-homogeneous vector b    
       Output : Solution vector, X 
  
       read matrix A
       read vector b
       [L,U] = LUDecompose(A)
       Y = forward-substitute(L,b)
       X = back-substitute(U,Y)          
      print X, "is solution vector"            
   

Java programming code for Solve System of Linear Equations by LU Decompose

 
import java.util.Arrays;
public class LUSolution {

 
 public static void main(String[] args) {
    
 double A [][]= {{2,4,6},{4,5,6},{3,1,-2} };
 double b[] = {24,18,4};  
  
        LUMatrix lu=new LUMatrix(A); 
        lu.decompose();
        Matrix L= lu.getL();
        Matrix U = lu.getU();
        
        System.out.println("Lower Triangular Matrix L");
        System.out.println(L.toString());
        
        System.out.println("Upper Triangular Matrix U");
        System.out.println(U.toString());
        
                
        System.out.println("verify that Matrix A = LU");
        System.out.println(MatrixOpr.multiply(L, U).toString());
        
        
        System.out.println(" Y = Lb");
        double Y[]=Subsitution.forward(L, b);
        System.out.println("Y =" +  Arrays.toString(Y));
        
        System.out.println(" X = UY");
        double X[]=Subsitution.backward(U, Y);                     
        System.out.println("Solution of Matrix A,  X =" 
                                             + Arrays.toString(X));                  
 }

}

Java program output of Solve System of Linear Equations by LU Decompose


Matrix A
2  4   6  
4  5   6
3  1  -2

 b = [24 18 4] 

Lower Triangular Matrix L
1.0  0.0  0.0  
0.5  1.0  0.0  
0.75  -1.8333333  1.0  

Upper Triangular Matrix U
4.0  5.0  6.0  
0.0  1.5  3.0  
0.0  0.0  -1.0  

verify that Matrix A = LU
4.0  5.0  6.0  
2.0  4.0  6.0  
3.0  1.0  -2.0  

Y = Lb
Y =[24.0, 6.0, -3.0]

X = UY
Solution of Matrix A,  X =[4.0, -2.0, 3.0]



Comments

Popular posts from this blog

Matrix Forward and Back Substitution

Chebyshev distance between two points

Complex number Multiplication and Division

Solving System of Linear Equations by Gauss Jordan Elimination