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
33 lines (28 loc) · 820 Bytes
/
cachematrix.R
File metadata and controls
33 lines (28 loc) · 820 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
## Functions for computing inverse matrix for given matrix, caching
## the result for future use within the program
## Special type of matrix, which can save also its inverse matrix
makeCacheMatrix <- function(x = matrix()) {
im <- NULL
set <- function(y) {
x <<- y
im <<- NULL
}
get <- function() x
setinverse <- function(inverse) im <<- inverse
getinverse <- function() im
list(set = set, get = get,
setinverse = setinverse,
getinverse = getinverse)
}
## Function for computing inverse matrix, caching the result within CacheMatrix
cacheSolve <- function(x, ...) {
im <- x$getinverse()
if(!is.null(im)) {
message("getting cached data")
return(im)
}
data <- x$get()
im <- solve(data, ...)
x$setinverse(im)
im
}