![]() |
In this article, we will explore various methods to convert a matrix into a lower triangular matrix in R programming language. What is a matrix?A matrix is a two-dimensional rectangular data structure, which is a collection of rows and columns. Representation of rows is horizontal and columns are vertical. A matrix can contain data of the same type such as numeric, character, and, logic. It is possible to perform various operations on matrices. These matrixes are very similar to the vectors but differ in their dimensionalities. Using the function ‘matrix()’ can create the matrix. Converting a matrix into various types of lower triangular matricesR language offers different types of lower triangular matrices. In the lower triangular matrix, we perform operations on above the principal diagonal. when a matrix is converted into a lower triangular, the data that is present above the principal diagonal is zero in every entry. Some of the types of lower triangular matrices are:
Lower triangular matrixA lower traingular matrix s a square matrix, whose elements are above the principal diagonal are zero. The syntax for lower traingular matrix is upper.tri(matrix)
In this example, we created 3*3 matrix and converted it as lower traingular matrix.
Output: [,1] [,2] [,3] [1,] 11 14 17 [2,] 12 15 18 [3,] 13 16 19 In this example, we created 5*5 matrix and converted it as lower traingular matrix.
Output: [,1] [,2] [,3] [,4] [,5] [1,] 1 6 11 16 21 [2,] 2 7 12 17 22 [3,] 3 8 13 18 23 [4,] 4 9 14 19 24 [5,] 5 10 15 20 25 Strictly lower triangular matrixStrictly lower triangular matrix is a square matrix where all the elements on or above the principal diagonal is zero. In this example, we created 5*5 matrix and converted it as strictly lower traingular matrix.
Output: [,1] [,2] [,3] [,4] [,5] [1,] 1 6 11 16 21 [2,] 2 7 12 17 22 [3,] 3 8 13 18 23 [4,] 4 9 14 19 24 [5,] 5 10 15 20 25 In this example, we created 3*3 matrix and converted it as strictly lower traingular matrix.
Output: [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 Unit lower traingular matrixA unit lower traingular matrix is a square matrix where all the diagonal elements are equal to 1 and above the diagonal are zeros. In this example, we created 5*5 matrix and converted it as unit lower traingular matrix.
Output: [,1] [,2] [,3] [,4] [,5]
[1,] 1 0 0 0 0
[2,] 1 1 0 0 0
[3,] 1 1 1 0 0
[4,] 1 1 1 1 0
[5,] 1 1 1 1 1
In this example, we created 3*3 matrix and converted it as unit lower traingular matrix.
Output: [1] "unit lower traingular matrix"
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 1 1 0
[3,] 1 1 1
ConclusionIn conclusion, we learned about converting a matrix into various lower triangular matrices. R language offers versatile tools while handling with the matrices. |
Reffered: https://www.geeksforgeeks.org
R Language |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 9 |