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
34 lines (29 loc) · 818 Bytes
/
cachematrix.R
File metadata and controls
34 lines (29 loc) · 818 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
34
## These functions give some benefit to caching the inverse of a matrix
## rather than computing it repeatedly
## Returns matrix object which can cache inversed matrix
makeCacheMatrix <- function(x = matrix()) {
solve <- NULL;
get <- function() { x };
set <- function(y) {
x <<- y;
solve <<- NULL;
};
getsolve <- function() { solve };
setsolve <- function(s) { solve <<- s };
list(get = get,
set = set,
getsolve = getsolve,
setsolve = setsolve);
}
## Returns inversed matrix of cacheMatrix object using caching mechanism
cacheSolve <- function(x, ...) {
s <- x$getsolve();
if (!is.null(s)) {
message("getting cached object");
return(s);
}
matrix <- x$get();
s <- solve(matrix);
x$setsolve(s);
s
}