File tree Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change 3
3
4
4
# # Write a short comment describing this function
5
5
6
- makeCacheMatrix <- function (x = matrix ()) {
7
-
6
+ makeCacheMatrix <- function ( dataMatrix = matrix () ) {
7
+ inverseMatrix <- NULL
8
+
9
+ set <- function ( newDataMatrix ) {
10
+ dataMatrix <<- newDataMatrix
11
+ inverseMatrix <<- NULL
12
+ }
13
+
14
+ get <- function () dataMatrix
15
+
16
+ setInverse <- function ( inverse ) inverseMatrix <<- inverse
17
+
18
+ getInverse <- function () inverseMatrix
19
+
20
+ list (set = set , get = get ,
21
+ setInverse = setInverse ,
22
+ getInverse = getInverse )
8
23
}
9
24
10
25
11
26
# # Write a short comment describing this function
12
27
13
28
cacheSolve <- function (x , ... ) {
14
29
# # Return a matrix that is the inverse of 'x'
30
+ inverse <- x $ getInverse()
31
+ if ( ! is.null( inverse ) ) {
32
+ message( " Getting cached data..." )
33
+ return ( inverse )
34
+ }
35
+ data <- x $ get()
36
+ inverse <- solve( data , ... )
37
+ x $ setInverse( inverse )
38
+ inverse
15
39
}
You can’t perform that action at this time.
0 commit comments