Skip to content

Commit 2e6091c

Browse files
committed
Adding comments and polishing cachematrix.R
1 parent 3908ddd commit 2e6091c

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

cachematrix.R

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
3-
4-
## Write a short comment describing this function
1+
## Functions for manipulating matrices that allow for their inverses to be
2+
## cached, saving computation time if the inverse of a matrix is queried more
3+
## often than the matrix is modified. The makeCacheMatrix function builds such a
4+
## matrix and the cacheSolve function returns its inverse.
55

6+
## Converts a standard matrix x to a matrix that allows for its inverse to be
7+
## cached. The original matrix x is unmodified, the converted matrix is returned
8+
## by the function.
69
makeCacheMatrix <- function(x = matrix()) {
710
m <- NULL
811
set <- function(y) {
912
x <<- y
1013
m <<- NULL
1114
}
1215
get <- function() x
13-
setmean <- function(mean) m <<- mean
14-
getmean <- function() m
16+
setinverse <- function(inverse) m <<- inverse
17+
getinverse <- function() m
1518
list(set = set, get = get,
16-
setmean = setmean,
17-
getmean = getmean)
19+
setinverse = setinverse,
20+
getinverse = getinverse)
1821
}
1922

20-
21-
## Write a short comment describing this function
22-
23+
## Takes a CacheMatrix x and returns its inverse. If the inverse is cached, no
24+
## recomputation will be required.
2325
cacheSolve <- function(x, ...) {
2426
## Return a matrix that is the inverse of 'x'
25-
m <- x$getmean()
27+
m <- x$getinverse()
2628
if(!is.null(m)) {
2729
message("getting cached data")
2830
return(m)
2931
}
3032
data <- x$get()
3133
m <- solve(data, ...)
32-
x$setmean(m)
34+
x$setinverse(m)
3335
m
3436
}

0 commit comments

Comments
 (0)