|
1 | 1 |
|
2 |
| -## This file is the solution to programming assignment 2 and contains 2 functions. |
| 2 | +## This file is the solution to programming assignment 2 and contains two functions. |
3 | 3 |
|
4 |
| -## Make a list of functions that work on a captured varible to store a matrix and a cached version of the inverse of the same matrix. |
5 |
| -## No computation in this funxtion, only getter & setter functions that work on the captured variable. |
| 4 | + |
| 5 | +## Make a list of functions that work on a captured varible. |
| 6 | +## Store a matrix and a cached version of the inverse of the same matrix. |
| 7 | +## No computation in this function, only getter & setter functions that work on the captured variable. |
6 | 8 |
|
7 | 9 | makeCacheMatrix <- function(x = matrix()) {
|
8 | 10 |
|
9 |
| - ## Store the cached inverse matrix "inside" this closure |
| 11 | + # Store the cached inverse matrix "inside" this closure (stored in the environment) |
10 | 12 | cache <- NULL
|
11 | 13 |
|
12 |
| - ## Getter / setter functions to return |
| 14 | + # Getter / setter functions to return |
13 | 15 | get <- function() x
|
14 | 16 | getInverse <- function() cache
|
15 | 17 | setInverse <- function(m) cache <<- m
|
16 | 18 |
|
17 |
| - ## return a list of functions, like the example code |
| 19 | + # Return a list of functions, like the example code |
18 | 20 | list(get = get, getInverse = getInverse, setInverse = setInverse)
|
19 | 21 | }
|
20 | 22 |
|
21 | 23 |
|
22 |
| -## Solve the inverse of a matrix, using the closue we created with makeCacheMatrix |
23 |
| -## If the cache is set return that. If not, solve() for matrix and return the result after setting the cache |
| 24 | +## Solve the inverse of a matrix, using the closure we created with makeCacheMatrix |
| 25 | +## If the cache is set return that. |
| 26 | +## If not, solve() for matrix and return the result after setting the cache |
24 | 27 |
|
25 | 28 | cacheSolve <- function(x, ...) {
|
26 | 29 |
|
27 |
| - inv <- x$getInverse() # # the varibale we will return after setting it to the correct matrix |
| 30 | + inv <- x$getInverse() # the varibale we will return after setting it to the correct matrix |
28 | 31 |
|
29 | 32 | if(is.null(inv)){
|
30 | 33 | # Nothing cached, solve and fill the cache
|
|
0 commit comments