Skip to content

Commit 9854e6b

Browse files
committed
All done!
1 parent 894f13f commit 9854e6b

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
README.html

cachematrix.R

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
11
## A couple of functions that cache the inverse of a matrix so that the cost of
22
## repetitive computation can be avoided
33

4-
## Write a short comment describing this function
4+
## makeCacheMatrix creates an object that can hold the inverse of a matrix.
5+
## get/set gets and sets the matrix
6+
## getinverse/setinverse gets and sets the inverse of the matrix set
57

68
makeCacheMatrix <- function(x = matrix()) {
7-
9+
i <- NULL
10+
set <- function(y) {
11+
x <<- y
12+
i <<- NULL
13+
}
14+
get <- function() x
15+
setinverse <- function(inverse) i <<- inverse
16+
getinverse <- function() i
17+
list(set = set, get = get,
18+
setinverse = setinverse,
19+
getinverse = getinverse)
820
}
921

1022

11-
## Write a short comment describing this function
23+
## cacheSolve returns the inverse of a matrix using the solve function. It
24+
## caches the result in a makeCacheMatrix object
1225

1326
cacheSolve <- function(x, ...) {
14-
## Return a matrix that is the inverse of 'x'
27+
i <- x$getinverse()
28+
if(!is.null(i)) {
29+
message("getting cached data")
30+
return(i)
31+
}
32+
data <- x$get()
33+
i <- solve(data, ...)
34+
x$setinverse(i)
35+
i
1536
}

0 commit comments

Comments
 (0)