File tree Expand file tree Collapse file tree 1 file changed +20
-20
lines changed Expand file tree Collapse file tree 1 file changed +20
-20
lines changed Original file line number Diff line number Diff line change 1
1
# # These functions are used to calculate the inverse of a matrix and cache it.
2
2
# # If the calculations is repeated with the same matrix it uses the cache value
3
- # # rather than recalculate it.
3
+ # # rather than recalculate it.
4
4
5
5
6
6
# # This function creates a special "matrix" object that cache its inverse
7
7
8
8
makeCacheMatrix <- function (x = matrix ()) {
9
9
m <- NULL
10
- set <- function (y ) {
11
- x <<- y
12
- m <<- NULL
13
- }
14
- get <- function () x
15
- setinverse <- function (solve ) m <<- solve
16
- getinverse <- function () m
17
- list (set = set , get = get ,
18
- setinverse = setinverse ,
19
- getinverse = getinverse )
10
+ set <- function (y ) {
11
+ x <<- y
12
+ m <<- NULL
13
+ }
14
+ get <- function () x
15
+ setinverse <- function (solve ) m <<- solve
16
+ getinverse <- function () m
17
+ list (set = set , get = get ,
18
+ setinverse = setinverse ,
19
+ getinverse = getinverse )
20
20
21
21
}
22
22
@@ -25,13 +25,13 @@ makeCacheMatrix <- function(x = matrix()) {
25
25
# # retrieve the inverse from the cache
26
26
27
27
cacheSolve <- function (x , ... ) {
28
- m <- x $ getinverse()
29
- if (! is.null(m )) {
30
- message(" getting cached data" )
31
- return (m )
32
- }
33
- data <- x $ get()
34
- m <- solve(data , ... )
35
- x $ setinverse(m )
36
- m
28
+ m <- x $ getinverse()
29
+ if (! is.null(m )) {
30
+ message(" getting cached data" )
31
+ return (m )
32
+ }
33
+ data <- x $ get()
34
+ m <- solve(data , ... )
35
+ x $ setinverse(m )
36
+ m
37
37
}
You can’t perform that action at this time.
0 commit comments