Skip to content

Latest commit

History

History
49 lines (43 loc) · 1.38 KB

File metadata and controls

49 lines (43 loc) · 1.38 KB

USAGE Examples :

Create a square matrix x

x <- matrix(rnorm(16), nrow = 4)

Make our CacheMatrix

cm <- makeCacheMatrix(x)

Get our matrix

cm$getMatrix()

 [,1] [,2] [,3] [,4]
[1,] -1.4332700 -1.1260479 -0.8502516 -0.567789
[2,] -0.2163094 -1.7524981 -0.4194068 -1.442623
[3,] -1.0437617 -0.3273858 -0.2062895 -0.637691
[4,] 0.5098000 0.2229530 0.2166387 -0.369119

Get the inverse matrix

cacheSolve(cm)

Calculate the inverse of the matrix...
[,1] [,2] [,3] [,4]
[1,] 0.5969354 -0.009156084 -1.1969154 1.185356
[2,] 1.1093224 -0.951691610 -0.1859315 2.334309
[3,] -3.3403496 1.198436085 2.4733969 -3.818661
[4,] -0.4659866 0.115890352 -0.3137416 -1.903272

Get the inverse matrix from the cache (2nd time call)

cacheSolve(cm)

Getting cached data...
[,1] [,2] [,3] [,4]
[1,] 0.5969354 -0.009156084 -1.1969154 1.185356
[2,] 1.1093224 -0.951691610 -0.1859315 2.334309
[3,] -3.3403496 1.198436085 2.4733969 -3.818661
[4,] -0.4659866 0.115890352 -0.3137416 -1.903272

Get the inverse matrix

cm$getInverseMatrix()

 [,1] [,2] [,3] [,4]
[1,] 0.5969354 -0.009156084 -1.1969154 1.185356
[2,] 1.1093224 -0.951691610 -0.1859315 2.334309
[3,] -3.3403496 1.198436085 2.4733969 -3.818661
[4,] -0.4659866 0.115890352 -0.3137416 -1.903272