R语言 计算矩阵的Choleski因式分解 – chol()函数
R语言中的 chol() 函数用于计算一个实数对称正无限方阵的Choleski因式分解。
语法: chol(x,…)
参数:
x: 一个存在方法的对象。默认的方法适用于实数对称的正无限矩阵
例1:
# 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:
# 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