Skip to content

Commit 72766a9

Browse files
committed
Programming Assignment 2
1 parent 860e056 commit 72766a9

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

cachematrix.R

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
## These functions are used to calculate the inverse of a matrix and cache it.
22
## If the calculations is repeated with the same matrix it uses the cache value
3-
## rather than recalculate it.
3+
## rather than recalculate it.
44

55

66
## This function creates a special "matrix" object that cache its inverse
77

88
makeCacheMatrix <- function(x = matrix()) {
99
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)
2020

2121
}
2222

@@ -25,13 +25,13 @@ makeCacheMatrix <- function(x = matrix()) {
2525
## retrieve the inverse from the cache
2626

2727
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
3737
}

0 commit comments

Comments
 (0)