Matrices
by
L Surya
Department of CSA
KL Deemed to be university
Vijayawada, AP, India
Department of computer science and application
Contents
Applications of matrices
Creation of a matrix in R
 Perform mathematical operations on matrices
Access the elements of a matrix
Department of computer science and application
Department of computer science 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
Applications of matrices
• Computer graphics
• Probability and statistics
• Game theory
• Algorithms
• Quantum mechanics
Matrix
Definition: Matrix is a collection of
elements of the same type and data
arranged in two dimensional.
[,1] [,2] [,3]
[1,] 10 11 12
[2,] 13 14 15
[3,] 16 17 18
[4,] 19 20 21
Matrix
[,1] [,2] [,3] [,4]
[1,] 100 101 102 103
[2,] 104 105 106 107
[3,] 108 109 110 111
[4,] 112 113 114 115
Department of computer science and technology
Matrix creation
A matrix is 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.
Matrix creation
> x
[,1] [,2] [,3]
[1,] 10 11 12
[2,] 13 14 15
[3,] 16 17 18
Department of computer science and technology
Matrix creation
[,1] [,2] [,3] [,4]
[1,] 100 101 102 103
[2,] 104 105 106 107
[3,] 108 109 110 111
[4,] 112 113 114 115
[,1] [,2] [,3]
[1,] 10 14 18
[2,] 11 15 19
[3,] 12 16 20
[4,] 13 17 21
Adding row & col names
[,1] [,2] [,3]
[1,] 10 11 12
[2,] 13 14 15
[3,] 16 17 18
[4,] 19 20 21
col1 col2 col3
row1 10 11 12
row2 13 14 15
row3 16 17 18
row4 19 20 21
Adding row & col names
Accessing the elements of 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]
Accessing the elements of 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
>
Operations on matrices
Operations that can be done on matrices are
Arithmetic operations
-->Addition
-->Subtraction
-->Multiplication
-->Division
Matrices
>x=matrix(c(10:18),nrow=3,
byrow=TRUE)
>y=matrix(c(1:9),nrow=3,
byrow=TRUE)
>
[,1] [,2] [,3]
[1,]
[2,]
[3,]
[,1] [,2] [,3]
[1,]
[2,]
[3,]
[,1] [,2] [,3]
[1,]
[2,]
[3,]
Thank You

Matrices(teaching)Matrices(teaching)Matrices(teaching)Matrices(teaching)Matrices(teaching)Matrices(teaching)Matrices(teaching) ppt.pptx

  • 1.
    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
  • 5.
    Matrix Definition: Matrix isa collection of elements of the same type and data arranged in two dimensional.
  • 6.
    [,1] [,2] [,3] [1,]10 11 12 [2,] 13 14 15 [3,] 16 17 18 [4,] 19 20 21 Matrix [,1] [,2] [,3] [,4] [1,] 100 101 102 103 [2,] 104 105 106 107 [3,] 108 109 110 111 [4,] 112 113 114 115 Department of computer science and technology
  • 7.
    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
  • 9.
    Matrix creation [,1] [,2][,3] [,4] [1,] 100 101 102 103 [2,] 104 105 106 107 [3,] 108 109 110 111 [4,] 112 113 114 115 [,1] [,2] [,3] [1,] 10 14 18 [2,] 11 15 19 [3,] 12 16 20 [4,] 13 17 21
  • 10.
    Adding row &col names [,1] [,2] [,3] [1,] 10 11 12 [2,] 13 14 15 [3,] 16 17 18 [4,] 19 20 21 col1 col2 col3 row1 10 11 12 row2 13 14 15 row3 16 17 18 row4 19 20 21
  • 11.
    Adding row &col names
  • 12.
    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
  • 15.
  • 16.