Matrices
by
L Surya
Department ofCSA
KL Deemed to be university
Vijayawada, AP, India
Department of computer science and application
2.
Contents
Applications of matrices
Creationof a matrix in R
Perform mathematical operations on matrices
Access the elements of a matrix
Department of computer science and application
3.
Department of computerscience and technology
Outcomes
• Know the applications of matrices
• Creating a matrix
• Perform mathematical operations on matrices
• Access the elements of a matrix
At the end of this lecture you will be
able to
4.
Applications of matrices
•Computer graphics
• Probability and statistics
• Game theory
• Algorithms
• Quantum mechanics
Matrix creation
A matrixis created using
The matrix() function.
Syntax:
matrix_name<-
matrix(data,nrow,ncol,byrow,dimnames)
Where
Data – means input
nrow- number of rows
ncol – number of columns
byrow- means logical . If TRUE then the input vector
elements are arranged by row.
dimnames-is the names for the rows and columns.
8.
Matrix creation
> x
[,1][,2] [,3]
[1,] 10 11 12
[2,] 13 14 15
[3,] 16 17 18
Department of computer science and technology
Accessing the elementsof matrix
Access the elements of a matrix by using
The column and row index of the element.
Syn:Matrix_name[row,column]
Ex: to access 3rd
row 2nd
column
>x[3,2]
13.
Accessing the elementsof matrix
[,1] [,2] [,3]
[1,] 10 11 12
[2,] 13 14 15
[3,] 16 17 18
[4,] 19 20 21
To access column
>
To access row column
>
To access only row
>
To access only column
>
14.
Operations on matrices
Operationsthat can be done on matrices are
Arithmetic operations
-->Addition
-->Subtraction
-->Multiplication
-->Division