Skip to content

Commit dd8abd3

Browse files
committed
Completes assignment 2
1 parent 7f657dd commit dd8abd3

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

cachematrix.R

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
## Put comments here that give an overall description of what your
22
## functions do
33

4-
## Write a short comment describing this function
5-
4+
## returns a list of functions to get/set an 'internal' matrix and get/set its inverse.
5+
## (get, set, getinv, setinv).
6+
## If the matrix is 'set' via this list's set function, the inverse matrix will be cleared.
67
makeCacheMatrix <- function(x = matrix()) {
8+
m <- NULL
9+
set <- function(y) {
10+
x <<- y
11+
m <<- NULL
12+
}
13+
get <- function() x
14+
setinv <- function(matinv) m <<- matinv
15+
getinv <- function() m
16+
list(set = set, get = get,
17+
setinv = setinv,
18+
getinv = getinv)
719

820
}
921

1022

11-
## Write a short comment describing this function
12-
23+
## Returns inverse of x, storing the computation of the inverse
24+
## x is not actually a matrix, but rather a list generated by makeCacheMatrix
1325
cacheSolve <- function(x, ...) {
26+
27+
m <- x$getinv()
28+
if(!is.null(m)) {
29+
message("getting cached data")
30+
return(m)
31+
}
32+
data <- x$get()
33+
m <- matrix(rev(c(data)), nrow=nrow(data), ncol=ncol(data))
34+
x$setinv(m)
35+
m
1436
## Return a matrix that is the inverse of 'x'
1537
}

0 commit comments

Comments
 (0)