forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcachematrix.R
34 lines (29 loc) · 887 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
## This file contains functions to contruct an inverted matrix and store it
## Below function will constructs the matrix functions and attributes
## The matrix needs to have equal dimensions
makeCacheMatrix <- function(x = matrix()) {
inverse_x <- NULL
set <- function(y) {
x <<- y
inverse_x <<- NULL
}
get <- function() x
setinverse <- function(solve) inverse_x <<- solve
getinverse <- function() inverse_x
list(set = set, get = get,
setinverse = setinverse,
getinverse = getinverse)
}
## Below function will return the cached inverse matrix if one is found
## If no cache is found it will create the inversed matrix
cacheSolve <- function(x, ...) {
inverse_x <- x$getinverse()
if(!is.null(inverse_x)) {
message("getting cached data")
return(inverse_x)
}
matrice <- x$get()
inverse_x <- solve(matrice)
x$setinverse(inverse_x)
inverse_x
}