Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c7853f7

Browse files
committed
Added summary comments
1 parent ee97e07 commit c7853f7

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

cachematrix.R

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,37 @@
1-
## Put comments here that give an overall description of what your
2-
## functions do
1+
## cacheMatrix, provides two functions that compute the inverse of a matrix and cache it
2+
# for future use. The first function makeCacheMatrix takes a matrix as a single argument.
3+
# The matrix is assumed to be inversible. It returns a list of four helper functions to get & set a
4+
# matrix, and to get and set its cached inverse
5+
# The second function cacheSolve computes the inverse of a matrix and returns its value
36

4-
## This function creates a special "matrix" object that can cache its inverse.
7+
8+
## This function creates a special "matrix" object that can cache its inverse. The function
9+
## is comprised of a list of four functions (set, get, setinverse, getinverse). get returns
10+
## the current matrix, set is use to set the matrix to a new matrix, getinverse returns the
11+
## cached copy of the inverse, setinverse sets the cache to the new value of the inverse
512

613
makeCacheMatrix <- function(x = matrix()) {
714
m <- NULL
15+
get <- function() x
816
set <- function(y) {
917
x <<- y
1018
m <<- NULL
1119
}
12-
get <- function() x
1320
setinverse <- function(inverse) m <<- inverse
1421
getinverse <- function() m
15-
list(set = set, get = get,
22+
list(get = get,
23+
set = set,
1624
setinverse = setinverse,
1725
getinverse = getinverse)
1826
}
1927

2028

2129
## This function computes the inverse of the special "matrix" returned by makeCacheMatrix above.
22-
## If the inverse has already been calculated (and the matrix has not changed), then the cachesolve
23-
## should retrieve the inverse from the cache.
30+
## If the inverse has already been calculated (and the matrix has not changed), then the cached copy
31+
## is returned. Otherwise we assume the current matrix is inversible and use solve(X) to inverse the
32+
## matrix and return the result
2433

2534
cacheSolve <- function(x, ...) {
26-
## Return a matrix that is the inverse of 'x'
2735
m <- x$getinverse()
2836
if(!is.null(m)) {
2937
message("getting cached data")

0 commit comments

Comments
 (0)