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]]