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
32 lines (28 loc) · 1017 Bytes
/
cachematrix.R
File metadata and controls
32 lines (28 loc) · 1017 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
## Put comments here that give an overall description of what your
## functions do
## Write a short comment describing this function
## This function returns a list of functions which can change the matrix and also store its inverse in cache
makeCacheMatrix <- function(x = matrix()) {
my_matrix_inverse=NULL
set<-function(decoy){
my_matrix<<-decoy
my_matrix_inverse<<-NULL
}
get<-function() my_matrix
set_inverse<-function(solve) my_matrix_inverse<<-solve
get_inverse<-function() my_matrix_inverse
list(set=set,get=get,set_inverse=set_inverse,get_inverse=get_inverse)
}
## Write a short comment describing this function
cacheSolve <- function(x, ...) {
my_matrix_inverse <- my_matrix$get_inverse()
if(!is.null(my_matrix_inverse)) {
message("getting cached data")
return(my_matrix_inverse)
}
data <- my_matrix$get()
my_matrix_inverse <- solve(data, ...)
my_matrix$set_inverse(my_matrix_inverse)
my_matrix_inverse
## Return a matrix that is the inverse of 'x'
}