File tree Expand file tree Collapse file tree 1 file changed +26
-6
lines changed Expand file tree Collapse file tree 1 file changed +26
-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
+ # # Calculate the inverse of a matrix. Use a cache structure to optimize computations
2
+ # #
3
3
4
- # # Write a short comment describing this function
4
+ # # Construct that stores a matrix and its inverse. If the inverse is not stored NULL is returned
5
5
6
6
makeCacheMatrix <- function (x = matrix ()) {
7
-
7
+ inv <- NULL
8
+ set <- function (y ){
9
+ x <<- y
10
+ inv <<- NULL
11
+ }
12
+
13
+ get <- function () x
14
+ setInverse <- function (toCache ) inv <<- toCache
15
+ getInverse <- function () inv
16
+
17
+ list (set = set , get = get , setInverse = setInverse , getInverse = getInverse )
8
18
}
9
19
10
20
11
- # # Write a short comment describing this function
21
+ # # Returns the inverse of a matrix. The result is cached.
12
22
13
23
cacheSolve <- function (x , ... ) {
14
- # # Return a matrix that is the inverse of 'x'
24
+ inverse <- x $ getInverse()
25
+ if (! is.null(inverse )){
26
+ message(" Cached Inverse" )
27
+ return (inverse );
28
+ }
29
+
30
+ original <- x $ get()
31
+ inverse <- solve(original )
32
+ x $ setInverse(inverse )
33
+
34
+ inverse
15
35
}
You can’t perform that action at this time.
0 commit comments