File tree Expand file tree Collapse file tree 1 file changed +30
-6
lines changed Expand file tree Collapse file tree 1 file changed +30
-6
lines changed Original file line number Diff line number Diff line change 1
- # # Put comments here that give an overall description of what your
2
- # # functions do
1
+ # # makeCacheMatrix takes an matrix and creates an object from which you
2
+ # # can get the matrix back but also the inverse of the matrix if it has
3
+ # # been computed and then by calling the cacheSolve you can compute the
4
+ # # inverse of the matrix or take it from the cache if it was already
5
+ # # computed
3
6
4
- # # Write a short comment describing this function
7
+ # # This function creates the special caching object
5
8
6
9
makeCacheMatrix <- function (x = matrix ()) {
7
-
10
+ inv <- NULL
11
+ setData <- function (y )
12
+ {
13
+ x <<- y
14
+ inv <<- NULL
15
+ }
16
+ getData <- function () x
17
+ setInv <- function (invMat ) inv <<- invMat
18
+ getInv <- function () inv
19
+ list (setData = setData , getData = getData , setInv = setInv , getInv = getInv )
8
20
}
9
21
10
22
11
- # # Write a short comment describing this function
23
+ # # This function will get you the inverse of a matrix but if that
24
+ # # was already computed then the computation is skipped and you get
25
+ # # the cached result
12
26
13
27
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
28
+ inv <- x $ getInv()
29
+ if (! is.null(inv ))
30
+ {
31
+ message(" getting cached inverse" )
32
+ return (inv )
33
+ }
34
+ # if nothing in cache then compute
35
+ data <- x $ getData()
36
+ inv <- solve(data )
37
+ x $ setInv(inv )
38
+ x $ getInv()
15
39
}
You can’t perform that action at this time.
0 commit comments