📜  在 R 编程中计算矩阵的 Choleski 因式分解 – chol()函数

📅  最后修改于: 2022-05-13 01:55:09.372000             🧑  作者: Mango

在 R 编程中计算矩阵的 Choleski 因式分解 – chol()函数

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

示例 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


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