Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7f657dd commit 391d012Copy full SHA for 391d012
cachematrix.R
@@ -4,12 +4,35 @@
4
## Write a short comment describing this function
5
6
makeCacheMatrix <- function(x = matrix()) {
7
-
+ MyInv <- NULL
8
+ set <- function(y) {
9
+ x <<- y
10
+ MyInv <<- NULL
11
+ }
12
+ get <- function() x
13
+ setInverse <- function(inverse) MyInv <<- inverse #calculate the inverse
14
+ getInverse <- function() MyInv
15
+ list(set = set,
16
+ get = get,
17
+ setInverse = setInverse,
18
+ getInverse = getInverse)
19
+
20
}
21
22
23
24
25
cacheSolve <- function(x, ...) {
26
## Return a matrix that is the inverse of 'x'
27
+ MyInv <- x$getInverse()
28
+ if (!is.null(MyInv)) {
29
+ message("getting cached data")
30
+ return(MyInv)
31
32
+ mat <- x$get()
33
+ MyInv <- solve(mat, ...)
34
+ x$setInverse(MyInv)
35
+ MyInv
36
37
38
0 commit comments