-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPA_2.R
More file actions
34 lines (30 loc) · 965 Bytes
/
PA_2.R
File metadata and controls
34 lines (30 loc) · 965 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
## makeCacheMatrix function creates a special matrix object that can cache its inverse.
makeCacheMatrix <- function(x = matrix()) {
inverse_X <- NULL
set <- function(y) {
x <<- y
inverse_X <<- NULL
}
get <- function() x
setInverse <- function(inverse) inverse_X <<- inverse
getInverse <- function() inverse_X
list(set = set,
get = get,
setInverse = setInverse,
getInverse = getInverse)
}
## cacheSolve function computes the inverse of the special "matrix" created by
## makeCacheMatrix above. If the inverse has already been calculated (and the
## matrix has not changed), then it should retrieve the inverse from the cache.
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
inverse_X <- x$getInverse()
if (!is.null(inverse_X)) {
message("getting cached data")
return(inverse_X)
}
mat <- x$get()
inverse_X <- solve(mat, ...)
x$setInverse(inverse_X)
inverse_X
}