|
1 |
| -## Put comments here that give an overall description of what your |
2 |
| -## functions do |
3 |
| - |
4 |
| -## Write a short comment describing this function |
5 | 1 |
|
| 2 | +# This is a generic cache object which has not changed |
| 3 | +# much from the original cacheVector. Infact it is generic |
| 4 | +# and can be simply a cacheObject. The logic of what is cached |
| 5 | +# is contained in cacheSolve |
6 | 6 | makeCacheMatrix <- function(x = matrix()) {
|
| 7 | + solveCache <- NULL |
| 8 | + get <- function() x |
| 9 | + # Set the Matrix, remove any old solved data |
| 10 | + set <- function(y) { |
| 11 | + x <<- y |
| 12 | + solveCache <<- NULL |
| 13 | + x |
| 14 | + } |
7 | 15 |
|
8 |
| -} |
| 16 | + # Set the Solve |
| 17 | + setSolve <- function(y) { |
| 18 | + solveCache <<- y |
| 19 | + solveCache |
| 20 | + } |
9 | 21 |
|
| 22 | + getSolve <- function() solveCache |
10 | 23 |
|
11 |
| -## Write a short comment describing this function |
| 24 | + list(get=get, set=set, getSolve=getSolve, setSolve=setSolve) |
| 25 | +} |
12 | 26 |
|
| 27 | + |
| 28 | +# This function contains the reposnbility of solving the inverse matrix itself |
| 29 | +# and updating the cache object with the result. If it is already solved |
| 30 | +# then simply return that value. |
13 | 31 | cacheSolve <- function(x, ...) {
|
14 |
| - ## Return a matrix that is the inverse of 'x' |
| 32 | + inverse <- x$getSolve() |
| 33 | + if (!is.null(inverse)) { |
| 34 | + message("Getting Cached Data") |
| 35 | + ## Return a matrix that is the inverse of 'x' |
| 36 | + return(inverse) |
| 37 | + } |
| 38 | + |
| 39 | + # Inverse must not yet be solved, lets solve and set it |
| 40 | + # Default return here from setSolve will returned the solved value |
| 41 | + x$setSolve(solve(x$get(), ...)) |
15 | 42 | }
|
0 commit comments