File tree Expand file tree Collapse file tree 1 file changed +38
-9
lines changed Expand file tree Collapse file tree 1 file changed +38
-9
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
3
-
4
- # # Write a short comment describing this function
5
-
6
- makeCacheMatrix <- function (x = matrix ()) {
1
+ # # This collection of functions gives us the ability to make more
2
+ # # efficient calls to retrieve an inverted matrix by caching the inverse
7
3
4
+ # # creates a special matrix that caches its inverse
5
+ makeCacheMatrix <- function (m = matrix ()) {
6
+ cachedInverse <- NULL
7
+
8
+ set <- function (newmatrix )
9
+ {
10
+ m <<- newmatrix
11
+ cachedInverse <<- NULL
12
+ }
13
+ setinverse <- function (mi )
14
+ {
15
+ cachedInverse <<- mi
16
+ }
17
+ getinverse <- function ()
18
+ {
19
+ cachedInverse
20
+ }
21
+
22
+ list (set = set , get = get , setinverse = setinverse , getinverse = getinverse )
8
23
}
9
24
10
25
11
- # # Write a short comment describing this function
26
+ # # Invert the matrix m, where m is a special matrix created by
27
+ # # the above makeCacheMatrix. The data in m is assumed to be invertable
12
28
13
- cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
29
+ cacheSolve <- function (m , ... ) {
30
+ # # Return a matrix that is the inverse of 'x'
31
+ cachedInverse <- m $ getInverse()
32
+
33
+ if (! is.null(m ))
34
+ {
35
+ message(" getting cached inverse" )
36
+ return (cachedInverse )
37
+ }
38
+ matrixData <- m $ get()
39
+
40
+ cachedInverse <- solve(matrixData )
41
+
42
+ m $ setinverse(cachedInverse )
43
+ cachedInverse
15
44
}
You can’t perform that action at this time.
0 commit comments