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
50 lines (37 loc) · 1.11 KB
/
cachematrix.R
File metadata and controls
50 lines (37 loc) · 1.11 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
##Matrix inversion is usually a costly computation and there may be some benefit to caching the inverse of a matrix rather than computing it repeatedly Your assignment is to write a pair of functions that
## Those functions cache the inverse of a matrix
## Write a short comment describing this function
## The following function creates a Matrix which can cache ist inverse, by using a third variable.
makeCacheMatrix <- function(x = matrix()) {
iMtx <- NULL
set <- function(y) {
x <<- y
iMtx <<- NULL
}
get <- function() {
x
}
setInverse <- function(ivs) {
iMtx <<- ivs
}
getInverse <- function() {
iMtx
}
list(set = set, get = get,
setInverse = setInverse,
getInverse = getInverse)
}
## Write a short comment describing this function
## The following function, computes or return(if it's cached) the inverse of returned matrix.
cacheSolve <- function(x, ...) {
## Return a matrix that is the inverse of 'x'
iMtx <- x$getInverse()
if (!is.null(iMtx)) {
message("getting cached data")
return (iMtx)
}
mtx <- x$get()
iMtx <- solve(mtx, ...)
x$setInverse(iMtx)
iMtx
}