# Ruby | Matrix lup_decomposition() function

• Last Updated : 07 Jan, 2020

The lup_decomposition() is an inbuilt method in Ruby returns the LUP decomposition of the given matrix.

Syntax: mat1.lup_decomposition()

Parameters: The function needs the matrix whose LUP decomposition is to be returned.

Return Value: It returns the LUP decomposition of the matrix.

Example 1:

 `#Ruby program for lup_decomposition() method in Matrix`` ` `#Include matrix``require ``"matrix"`` ` `#Initialize a matrix``    ``mat1``    ``= Matrix[[ 1, 21 ], [ 31, 18 ]]`` ` `#Prints the decomposition``      ``puts` `mat1.lup_decomposition()`

Output:

```Matrix[[1, 0], [1/31, 1]]
Matrix[[31, 18], [0, 633/31]]
Matrix[[0, 1], [1, 0]]
```

Example 2:

 `#Ruby program for lup_decomposition() method in Matrix`` ` `#Include matrix``require ``"matrix"`` ` `#Initialize a matrix``    ``mat1``    ``= Matrix[[ 1, 0, 0 ], [ 2, 3, 0 ], [ 31, 18, 19 ]]`` ` `#Prints the decomposition``      ``puts` `mat1.lup_decomposition()`

Output:

```Matrix[[1, 0, 0], [2/31, 1, 0], [1/31, -6/19, 1]]
Matrix[[31, 18, 19], [0, 57/31, -38/31], [0, 0, -1/1]]
Matrix[[0, 0, 1], [0, 1, 0], [1, 0, 0]]```
My Personal Notes arrow_drop_up