当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R语言 chol()用法及代码示例


R 语言中的 chol() 函数用于计算实对称 positive-definite 方阵的 Choleski 分解。

用法: chol(x, …)
参数: 
x: an object for which a method exists. The default method applies to real symmetric, positive-definite matrices 
 

范例1:

Python3


# R program to illustrate
# chol function
 
# Initializing a matrix with
# 2 rows and 2 columns
x <- matrix(c(8, 1, 1, 4), 2, 2)
 
# Getting the matrix representation
x
 
# Calling the chol() function
y <- chol(x)
 
# Getting the Choleski factorization
# of the specified matrix
y

输出:



     [, 1] [, 2]
[1, ]    8    1
[2, ]    1    4

         [, 1]      [, 2]
[1, ] 2.828427 0.3535534
[2, ] 0.000000 1.9685020

范例2:

Python3


# R program to illustrate
# chol function
 
# Initializing a matrix with
# 2 rows and 2 columns
x <- matrix(c(1, 2, 3, 4), 2, 2)
 
# Getting the matrix representation
x
 
# Calling the chol() function
y <- chol(x)
 
# Getting the Choleski factorization
# of the specified matrix
y

输出:

     [, 1] [, 2]
[1, ]    1    3
[2, ]    2    4

Error in chol.default(x):
  the leading minor of order 2 is not positive definite
Calls:chol -> chol.default
Execution halted




相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 Compute Choleski factorization of a Matrix in R Programming – chol() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。