forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcachematrix.R
More file actions
35 lines (32 loc) · 1.13 KB
/
Copy pathcachematrix.R
File metadata and controls
35 lines (32 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
## This function creates an enhanced matrix (holder) that has following functions:
## get/set the value of the matrix and get/set the value of the inverse matrix
## Courtesy (a.k.a copy-pasta of the assignment example)
makeCacheMatrix <- function(x = matrix()) {
m <- NULL
# getter and setter for the matrix value
get <- function() x
set <- function(y) {
x <<- y
m <<- NULL
}
# getter and setter for the inverse matrix value
getInverseMatrix <- function() m
setInverseMatrix <- function(inverseMatrix) m <<- inverseMatrix
# returing list of the previous functions
list(get = get, set = set, getInverseMatrix = getInverseMatrix, setInverseMatrix = setInverseMatrix)
}
## This function computes the inverse matrix, pushes it to the cache and returns the result
## or it just returns the previously cached result
## Courtesy (a.k.a copy-pasta of the assignment example)
cacheSolve <- function(x, ...) {
m <- x$getInverseMatrix()
if(!is.null(m)) {
message("getting cached data")
return(m)
}
data <- x$get()
m <- solve(data, ...)
x$setInverseMatrix(m)
## Return a matrix that is the inverse of 'x'
m
}