File tree Expand file tree Collapse file tree 2 files changed +35
-6
lines changed Expand file tree Collapse file tree 2 files changed +35
-6
lines changed Original file line number Diff line number Diff line change 1+ Version: 1.0
2+
3+ RestoreWorkspace: Default
4+ SaveWorkspace: Default
5+ AlwaysSaveHistory: Default
6+
7+ EnableCodeIndexing: Yes
8+ UseSpacesForTab: Yes
9+ NumSpacesForTab: 2
10+ Encoding: UTF-8
11+
12+ RnwWeave: Sweave
13+ LaTeX: pdfLaTeX
Original file line number Diff line number Diff line change 1- # # Put comments here that give an overall description of what your
2- # # functions do
3-
4- # # Write a short comment describing this function
1+ # # at first we create a special "matrix" object that can cache its inverse
52
63makeCacheMatrix <- function (x = matrix ()) {
7-
4+ inv <- NULL
5+ set <- function (y ){
6+ x <<- y
7+ inv <<- NULL
8+ }
9+ get <- function () x
10+ setInverse <- function (solveMatrix ) inv <<- solveMatrix
11+ getInverse <- function () inv
12+ list (set = set , get = get ,
13+ setInverse = setInverse ,
14+ getInverse = getInverse )
815}
916
1017
11- # # Write a short comment describing this function
18+ # # This function computes the inverse of the special "matrix" if it's not available in cache
1219
1320cacheSolve <- function (x , ... ) {
1421 # # Return a matrix that is the inverse of 'x'
22+ inv <- x $ getInverse()
23+ if (! is.null(inv )){
24+ message(" getting data from cache" )
25+ return (inv )
26+ }
27+ data <- x $ get()
28+ inv <- solve(data )
29+ x $ setInverse(inv )
30+ inv
1531}
You can’t perform that action at this time.
0 commit comments