當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Ruby Matrix lup_decomposition()用法及代碼示例

lup_decomposition()是Ruby中的內置方法,它返回給定矩陣的LUP分解。

用法: mat1.lup_decomposition()

參數:函數需要返回其LUP分解的矩陣。


返回值:返回矩陣的LUP分解。

例子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()

輸出

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

例子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()

輸出

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


相關用法


注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Ruby | Matrix lup_decomposition() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。