Skip to content

Commit fac1c72

Browse files
committed
* Initial implementation of makeCacheMatrix and cacheSolve for R Programming programming assignment 2/Peer Assessment project
1 parent 9b22d21 commit fac1c72

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

cachematrix.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,28 @@
55

66
makeCacheMatrix <- function(x = matrix()) {
77

8+
m <- NULL
9+
get <- function() x
10+
setinverse <- function(inverse) m <<- inverse
11+
getinverse <- function() m
12+
13+
list(get = get,
14+
setinverse = setinverse,
15+
getinverse = getinverse)
816
}
917

1018

1119
## Write a short comment describing this function
1220

1321
cacheSolve <- function(x, ...) {
1422
## Return a matrix that is the inverse of 'x'
23+
m <- x$getinverse()
24+
if (!is.null(m)) {
25+
message("Getting cached data")
26+
return(m)
27+
}
28+
data <- x$get()
29+
m <- solve(data)
30+
x$setinverse(m)
31+
m
1532
}

0 commit comments

Comments
 (0)