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 (28 loc) · 891 Bytes
/
Copy pathcachematrix.R
File metadata and controls
33 lines (28 loc) · 891 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
## Put comments here that give an overall description of what your
## functions do
## Creates a cacheable 'matrix' object.
makeCacheMatrix <- function(x = matrix()) {
invr <- NULL
set <- function(y) {
x <<- y
invr <<- NULL
}
get <- function() x
setinverse <- function(inverse) invr <<- inverse
getinverse <- function() invr
list( set = set, get = get, setinverse = setinverse, getinverse = getinverse
}
## Calculates the inverse of the matrix object, but only if it has not already been calculated.
## If there is a cached version, this is returned preceeded by the text 'getting cached data'.
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x' - this is 'invr'
invr <- x$getinverse()
if(!is.null(invr)) {
message("getting cached data")
return(invr)
}
data <- x$get()
invr <- solve(data)
x$setinverse(invr)
invr
}