|
1 |
| -## Put comments here that give an overall description of what your |
2 |
| -## functions do |
| 1 | +## Implementation of functions exibiting caching of difficult to |
| 2 | +## calculate values. This is done by using to <<- operator to save |
| 3 | +## values calculated in nested functions to the parent function's |
| 4 | +## scope, allowing other nested values to work with these values. |
3 | 5 |
|
4 |
| -## Write a short comment describing this function |
5 | 6 |
|
| 7 | +## This function takes a matrix as an argument. I returns an "object" |
| 8 | +## that provides a series of functions for retrieving and setting the |
| 9 | +## matrix and it's inverse. It does not however calculate its own |
| 10 | +## inverse. The set() function is also responsible for setting the |
| 11 | +## inverse of the matrix to null. This is done so that other functions |
| 12 | +## working with these "objects" whether to set the inverse. |
6 | 13 | makeCacheMatrix <- function(x = matrix()) {
|
7 |
| - |
| 14 | + inverse <- NULL |
| 15 | + get <- function(){ |
| 16 | + x |
| 17 | + } |
| 18 | + getInverse <- function(){ |
| 19 | + inverse |
| 20 | + } |
| 21 | + set <- function(y){ |
| 22 | + x <<- y |
| 23 | + inverse <<- NULL |
| 24 | + } |
| 25 | + setInverse <- function(m) inverse <<- m |
| 26 | + list(get = get, getInverse = getInverse, set = set, setInverse = setInverse) |
8 | 27 | }
|
9 | 28 |
|
10 | 29 |
|
11 |
| -## Write a short comment describing this function |
12 |
| - |
13 |
| -cacheSolve <- function(x, ...) { |
14 |
| - ## Return a matrix that is the inverse of 'x' |
| 30 | +## This function receives a matrix "object" and is responsible |
| 31 | +## computing the inverse of the "objects's" matrix. It ONLY does this |
| 32 | +## however, if the inverse of the "object's" matrix is null. |
| 33 | +cacheSolve <- function(x) { |
| 34 | + i <- x$getInverse() |
| 35 | + if(is.null(i)) { |
| 36 | + i <<- solve(x$get()) |
| 37 | + } |
| 38 | + i |
15 | 39 | }
|
0 commit comments