Skip to content

Commit cbc64b9

Browse files
committed
Implementation of makeCacheMatrix
1 parent 7f657dd commit cbc64b9

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

cachematrix.R

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,34 @@
33

44
## Write a short comment describing this function
55

6+
# This function creates a special matrix object, which inverse will be cached, if computed using cacheSolve
7+
# x is the matrix you want to allow to be cached
68
makeCacheMatrix <- function(x = matrix()) {
7-
9+
# initialize the variable which will store the inversed cached value
10+
# initially do not assign any value (it will be lazily assigned when cacheSolve is called)
11+
inversedCache <- NULL
12+
13+
# changes the stored matrix to a different one
14+
# cleares cache
15+
set <- function(newMatrix) {
16+
x <<- newMatrix
17+
inversedCache <<- NULL
18+
}
19+
20+
# returns the backend matrix
21+
get <- function() x
22+
23+
# returns the cached inverse. Cached inverse will be NULL if it has
24+
# not been computed yet
25+
getinverse <- function() inversedCache
26+
27+
# sets the cached inverse
28+
setinverse <- function(inverse) inversedCache <<- inverse
29+
30+
# returns a 'public API' of this makeCacheMatrix
31+
list(set = set, get = get,
32+
getinverse = getinverse,
33+
setinverse = setinverse)
834
}
935

1036

0 commit comments

Comments
 (0)