forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcachematrix.R
More file actions
47 lines (35 loc) · 1.06 KB
/
cachematrix.R
File metadata and controls
47 lines (35 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
## Put comments here that give an overall description of what your
## functions do
## Write a short comment describing this function
makeCacheMatrix <- function(sk = matrix()) {
skm <- NULL
set <- function(y) {
sk <<- y
skm <<- NULL
}
## provide other utility functions for the matrixinverse
## return the matrix value
get <- function() sk
## set the inverse of the matrix
setinverse <- function(skz) skm <<- skz
## get the inverse of the matrix
getinverse <- function() skm
## retun the list of functions supported.
list(set = set, get = get,
setinverse = setinverse,
getinverse = getinverse)
}
## Write a short comment describing this function
cacheSolve <- function(skcache, ...) {
## get the inverse first. it is true, no need to do the inverse again.
skm <- skcache$getinverse()
if(!is.null(skm)) {
message("I am getting cached data")
return(skm)
}
## nothing in the cache...do the inverse and set it to the cache.
skdata <- skcache$get()
skm <- solve(skdata)
skcache$setinverse(skm)
skm
}