forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cachematrix.R
37 lines (26 loc) · 920 Bytes
/
cachematrix.R
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
## This file contains functions for working with cached inversed matrix
## Creates a special "matrix" object that can cache its inverse
makeCacheMatrix <- function(x = matrix()) {
inversed <- NULL
set <- function(y) {
x <<- y
inversed <<- NULL
}
get <- function() x
setInversed <- function(inv) inversed <<- inv
getInversed <- function() inversed
list(set = set, get = get, setInversed = setInversed, getInversed = getInversed)
}
## Returns matrix that is the inverse of 'x', matrix created by makeCacheMatrix() function
## that is able to cache it's inverse
cacheSolve <- function(x, ...) {
inversedMatrix <- x$getInversed()
if(!is.null(inversedMatrix)) {
message("getting cached data")
return(inversedMatrix)
}
data <- x$get()
inversedMatrix <- solve(data, ...)
x$setInversed(inversedMatrix)
inversedMatrix
}