File tree Expand file tree Collapse file tree 1 file changed +33
-8
lines changed
Expand file tree Collapse file tree 1 file changed +33
-8
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+ # # object to contain matrix and it's
2+ # # inverse (if computed)
33
4- # # Write a short comment describing this function
5-
6- makeCacheMatrix <- function (x = matrix ()) {
4+ makeCacheMatrix <- function (actual = matrix ()) {
5+ inverse <- NULL
6+ set <- function (x ) {
7+ actual <<- x
8+ inverse <<- NULL
9+ }
10+ get <- function () {
11+ actual
12+ }
713
14+ setInverse <- function (i ) {
15+ inverse <<- i
16+ }
17+ getInverse <- function () {
18+ inverse
19+ }
20+ list (set = set , get = get ,
21+ setInverse = setInverse ,
22+ getInverse = getInverse )
823}
924
10-
11- # # Write a short comment describing this function
25+ # # method to get inverse. If not computed,
26+ # # it will stor it in cache. If previously
27+ # # computed, it will use cache
1228
1329cacheSolve <- function (x , ... ) {
14- # # Return a matrix that is the inverse of 'x'
30+ inverse <- x $ getInverse()
31+
32+ if (is.null(inverse )) {
33+ actual <- x $ get()
34+ if (dim(actual )[1 ] == dim(actual )[2 ]) {
35+ inverse <- solve(actual )
36+ x $ setInverse(inverse )
37+ }
38+ }
39+ inverse
1540}
You can’t perform that action at this time.
0 commit comments