# Compute Choleski factorization of a Matrix in R Programming – chol() Function

`chol()` function in R Language is used to compute the Choleski factorization of a real symmetric positive-definite square matrix.

Syntax: chol(x, …)

Parameters:
x: an object for which a method exists. The default method applies to real symmetric, positive-definite matrices

Example 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 spcified matrix ` `y `

Output:

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

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

Example 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 spcified matrix ` `y `

Output:

```     [, 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
```
My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.