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
39 lines (32 loc) · 1.24 KB
/
cachematrix.R
File metadata and controls
39 lines (32 loc) · 1.24 KB
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
38
39
## Put comments here that give an overall description of what your
## functions do
## This is a function sets and gets the value of the matrix and sets
## and gets the inverse of a matrix.
makeCacheMatrix <- function(x = matrix()) {
c <- NULL
set <- function(y) {
x <<- y
c <<- NULL
}
get <- function() x
setinverse <- function(solve) c <<- solve
getinverse <- function() c
list(set = set, get = get,
setinverse = setinverse,
getinverse = getinverse )
}
## This function checks to see if the inverse of the matrix
## has been calculated and if not calculates the inverse.
## If it has been calculated before it retrieves the cached inverse calculation.
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
c <- x$getinverse()
if(!is.null(c)) {
message("getting cached data")
return(c)
}
data <- x$get()
c <- solve(data, ...)
x$setinverse(c)
c
}