forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcachematrix.R
36 lines (29 loc) · 901 Bytes
/
cachematrix.R
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
## Put comments here that give an overall description of what your
## functions do
## Create a special matrix object with get, set a matrix and get, set its inverse
makeCacheMatrix <- function(x = matrix()) {
im <- NULL
set <- function(y) {
x <<- y
im <<- NULL
}
get <- function() x
setim <- function(inverseMatrix) im <<- inverseMatrix
getim <- function() im
list(set = set, get = get,
setim = setim,
getim = getim)
}
## Calculate and cache a matrix's inverse
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
im <- x$getim()
if (!is.null(im)) {
message("getting cached data")
return(im)
}
matrix <- x$get()
im <- solve(matrix)
x$setim(im)
im
}