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
34 lines (29 loc) · 733 Bytes
/
cachematrix.R
File metadata and controls
34 lines (29 loc) · 733 Bytes
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
## This function basically inverses a matrix and saves it
makeCacheMatrix <- function(x = matrix()) {
ch <- NULL
setMatrix <- function(newone) {
x <<- newone
ch <<- NULL
}
getMatrix <- function() {
x
}
cacheInverse <- function(solve) {
ch <<- solve
}
getInverse <- function() {
ch
}
list(setMatrix = setMatrix, getMatrix = getMatrix, cacheInverse = cacheInverse, getInverse = getInverse)
}
## In case nothing has been changed, the inverse of the matrix is retrived from the chache.
cacheSolve <- function(x, ...) {
inverse <- x$getInverse()
if(!is.null(inverse)) {
return(inverse)
}
data <- x$getMatrix()
inverse <- solve(data)
x$cacheInverse(inverse)
inverse
}