File tree Expand file tree Collapse file tree 1 file changed +28
-28
lines changed Expand file tree Collapse file tree 1 file changed +28
-28
lines changed Original file line number Diff line number Diff line change 8
8
# # cache its inverse.
9
9
# #
10
10
makeCacheMatrix <- function (matrix_val = matrix ()) {
11
- inverse_val <- NULL
12
- set <- function (new_matrix ) {
13
- matrix_val <<- new_matrix
14
- inverse_val <<- NULL
15
- }
16
- get <- function () {
17
- matrix_val
18
- }
19
- setInverse <- function (updated ) {
20
- inverse_val <<- updated
21
- }
22
- getInverse <- function () {
23
- inverse_val
24
- }
25
- list (set = set ,
26
- get = get ,
27
- setInverse = setInverse ,
28
- getInverse = getInverse )
11
+ inverse_val <- NULL
12
+ set <- function (new_matrix ) {
13
+ matrix_val <<- new_matrix
14
+ inverse_val <<- NULL
15
+ }
16
+ get <- function () {
17
+ matrix_val
18
+ }
19
+ setInverse <- function (updated ) {
20
+ inverse_val <<- updated
21
+ }
22
+ getInverse <- function () {
23
+ inverse_val
24
+ }
25
+ list (set = set ,
26
+ get = get ,
27
+ setInverse = setInverse ,
28
+ getInverse = getInverse )
29
29
}
30
30
31
31
@@ -37,14 +37,14 @@ makeCacheMatrix <- function(matrix_val = matrix()) {
37
37
# # but the result will be stored in the matrix object for later use.
38
38
# #
39
39
cacheSolve <- function (x , ... ) {
40
- # # Return a matrix that is the inverse of 'x'
41
- m <- x $ getInverse()
42
- if (is.null(m )) {
43
- data <- x $ get()
44
- m <- solve(data , ... )
45
- x $ setInverse(m )
46
- } else {
47
- message(" getting cached data" )
48
- }
49
- m
40
+ # # Return a matrix that is the inverse of 'x'
41
+ m <- x $ getInverse()
42
+ if (is.null(m )) {
43
+ data <- x $ get()
44
+ m <- solve(data , ... )
45
+ x $ setInverse(m )
46
+ } else {
47
+ message(" getting cached data" )
48
+ }
49
+ m
50
50
}
You can’t perform that action at this time.
0 commit comments