红宝石 |矩阵 lup()函数
lup()是 Ruby 中的内置方法,返回给定矩阵的 LUP 分解。
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.
示例 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()
输出:
Matrix[[1, 0], [1/31, 1]]
Matrix[[31, 18], [0, 633/31]]
Matrix[[0, 1], [1, 0]]
示例 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()
输出:
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]]