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
37 lines (30 loc) · 741 Bytes
/
cachematrix.R
File metadata and controls
37 lines (30 loc) · 741 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
34
35
36
37
## This is a programming assignment for a Coursera Data Scientist Course
## The goal of these functions are to cache the inverse of a matrix.
## This function caches the Matrix
makeCacheMatrix <- function(x = matrix()) {
b <- NULL
set <- function(y) {
x <<- y
b <<- NULL
}
get <- function() x
setinverse <- function(inverse) b <<- solve(x)
getinverse <- function() b
list(set = set, get = get,
setinverse = setinverse,
getinverse = getinverse)
}
}
## This function caches the inverse
cacheSolve <- function(x, ...) {
b <- x$getinverse()
if(!is.null(b)) {
message("Getting cached data...")
return(b)
}
data <- x$get()
b <- inverse(data, ... )
x$setinverse(b)
b
}
}