File tree Expand file tree Collapse file tree 1 file changed +34
-6
lines changed Expand file tree Collapse file tree 1 file changed +34
-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
3
1
4
- # # Write a short comment describing this function
2
+ # # Creates a wrapper around a a matrix
5
3
6
- makeCacheMatrix <- function (x = matrix ()) {
4
+ makeCacheMatrix <- function (input = matrix ()) {
5
+ inverse <- NULL
6
+ set <- function (y ) {
7
+ input <<- x
8
+ inverse <<- NULL
9
+ }
7
10
11
+ get <- function () {
12
+ input
13
+ }
14
+
15
+ setInverse <- function (inv ) {
16
+ inverse <<- inv
17
+ }
18
+
19
+ getInverse <- function () {
20
+ inverse
21
+ }
22
+
23
+ list (set = set , get = get ,
24
+ setInverse = setInverse ,
25
+ getInverse = getInverse )
8
26
}
9
27
10
28
11
- # # Write a short comment describing this function
29
+ # # Returns inverse of matrix 'x' from the cache if available
30
+ # # Otherwise computes and caches the inverse
12
31
13
32
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
33
+ inverse <- x $ getInverse()
34
+ if (! is.null(inverse )) {
35
+ message(" getting cached data" )
36
+ return (inverse )
37
+ }
38
+
39
+ input <- x $ get()
40
+ inverse <- solve(input , ... )
41
+ x $ setInverse(inverse )
42
+ inverse
15
43
}
You can’t perform that action at this time.
0 commit comments