|
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 |
3 | 6 |
|
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 |
5 | 12 |
|
6 | 13 | makeCacheMatrix <- function(x = matrix()) {
|
7 | 14 | m <- NULL
|
| 15 | + get <- function() x |
8 | 16 | set <- function(y) {
|
9 | 17 | x <<- y
|
10 | 18 | m <<- NULL
|
11 | 19 | }
|
12 |
| - get <- function() x |
13 | 20 | setinverse <- function(inverse) m <<- inverse
|
14 | 21 | getinverse <- function() m
|
15 |
| - list(set = set, get = get, |
| 22 | + list(get = get, |
| 23 | + set = set, |
16 | 24 | setinverse = setinverse,
|
17 | 25 | getinverse = getinverse)
|
18 | 26 | }
|
19 | 27 |
|
20 | 28 |
|
21 | 29 | ## 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 |
24 | 33 |
|
25 | 34 | cacheSolve <- function(x, ...) {
|
26 |
| - ## Return a matrix that is the inverse of 'x' |
27 | 35 | m <- x$getinverse()
|
28 | 36 | if(!is.null(m)) {
|
29 | 37 | message("getting cached data")
|
|
0 commit comments