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 (30 loc) · 1.01 KB
/
Copy pathcachematrix.R
File metadata and controls
33 lines (30 loc) · 1.01 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
## Next functions are used to produce inverse of provided matrix,
## cache it and provide the inverse matrix from cache if demanded for second time.
## Function creates variables matrix and inverse
## and a list of functions that set or get values to these variables
makeCacheMatrix <- function(matrix = matrix()) {
inverse <- NULL
set <- function(y) {
matrix <<- y
inverse <<- NULL
}
get <- function() matrix
setinverse <- function(z) inverse <<- z
getinverse <- function() inverse
list(set = set, get = get,
setinverse = setinverse,
getinverse = getinverse)
}
## Takes list created by makeCacheMatrix function and produces inverse for a matrix
## stored in variable matrix or take inverse from cache if it exists
cacheSolve <- function(x, ...) {
inverse <- x$getinverse()
if(!is.null(inverse)) {
message("getting cached data")
return(inverse)
}
data <- x$get()
inverse <- solve(data, ...)
x$setinverse(inverse)
inverse
}