# Matlab – Solve linear equation system by given LU decomposition and vector of constants

linear-algebramatlabmatrix-decompositionmatrix-factorization

Given `L` and `U` LU decomposition and vector of constants `b` such that `LU*x=b` , is there any built in function which find the `x` ? Mean something like –

``````X = functionName(L,U,b)
``````

Note that in both `L` and `U` we are dealing with triangular matrices which can be solved directly by forward and backward substitution without using the Gaussian elimination process.

Edit :

Solving this linear equation system should be according to the following steps –

``````1. define y - s.t Ux=y
2. solve Ly=b by forward substitution
3. solve Ux=y by backward substitution
4. return y
``````

Edit 2 :

I found linalg::matlinsolveLU but I didn't try it cause I have too old version (`R2010a`) . Is it working for anyone ?

#### Best Solution

If you have:

``````A = rand(3);
b = rand(3,1);
``````

then the solution to the system can be simply computed as:

``````x = A\b
``````

Or if you already have an LU decomposition of A, then:

``````[L,U] = lu(A);
xx = U\(L\b)
``````

the `mldivide` function is smart enough to detect that the matrix is triangular and chose an algorithm accordingly (forward/backward substitution)