# Ruby | Matrix lup() function

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

Syntax: mat1.lup()

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() method in Matrix ` ` `  `#Include matrix ` `require ``"matrix"` ` `  `#Initialize a matrix ` `    ``mat1 ` `    ``= Matrix[[ 1, 21 ], [ 31, 18 ]] ` ` `  `#Prints the decomposition ` `      ``puts` `mat1.lup() `

Output:

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

Example 2:

 `#Ruby program for lup() 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() `

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

The function of education is to teach one to think intensively and to think critically

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.