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
33 lines (30 loc) · 738 Bytes
/
Copy pathcachematrix.R
File metadata and controls
33 lines (30 loc) · 738 Bytes
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
## makeCacheMatrix makes matrix based object that may cache its inverse
makeCacheMatrix <- function(x = matrix()) {
mm <- NULL
set <- function(y) {
x <<- y
mm <<- NULL
}
## get the matrix value.
get <- function() x
## set the matrix inverse.
setinv <- function(i) mm <<- i
getinv <- function() mm
## get the the matrix inverse.
list(set = set, get = get,
setinv = setinv,
getinv = getinv)
}
## cacheSolve calculate invers for matrix created by makeCacheMatrix
cacheSolve <- function(x, ...) {
## Check if matrix already has inverse
mm <- x$getinv()
if(!is.null(mm)) {
message("getting cached data")
return(mm)
}
data <- x$get()
mm <- solve(data, ...)
x$setinv(mm)
mm
}