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
29 lines (27 loc) · 789 Bytes
/
cachematrix.R
File metadata and controls
29 lines (27 loc) · 789 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
## this file allows for a cached retrieval of an inverted matrix.
## creates an object representing a matrix with an precomputed inverted matrix.
makeCacheMatrix <- function(m = matrix()) {
mi <- NULL
set <- function(y) {
m <<- y
mi <<- NULL
}
get <- function() m
setinverse <- function(inverse) mi <<- inverse
getinverse <- function() mi
list(set = set, get = get,
setinverse = setinverse,
getinverse = getinverse)
}
## computes the inverted matrix if it has not been cached yet. Returns the inverted matrix.
cacheSolve <- function(m, ...) {
inverse <- m$getinverse()
if(!is.null(inverse)) {
message("getting cached data")
return(inverse)
}
thematrix <- m$get()
inverse <- solve(thematrix, ...)
m$setinverse(inverse)
inverse
}