File tree Expand file tree Collapse file tree 1 file changed +25
-7
lines changed Expand file tree Collapse file tree 1 file changed +25
-7
lines changed Original file line number Diff line number Diff line change 1- # # Put comments here that give an overall description of what your
2- # # functions do
3-
4- # # Write a short comment describing this function
1+ # # The following functions can create matrix which will cache its inverse
2+ # # for quick "calculation" in future calls.
53
4+ # # Make a matrix which can store a value for its inverse
5+ # # instead of solving for it every time.
66makeCacheMatrix <- function (x = matrix ()) {
7-
7+ s <- NULL
8+ set <- function (y ) {
9+ x <<- y
10+ s <<- NULL
11+ }
12+ get <- function () x
13+ setsolve <- function (solve ) s <<- solve
14+ getsolve <- function () s
15+ list (set = set , get = get ,
16+ setsolve = setsolve ,
17+ getsolve = getsolve )
818}
919
1020
11- # # Write a short comment describing this function
12-
21+ # # Calculate and cache the inverse of a matrix.
1322cacheSolve <- function (x , ... ) {
1423 # # Return a matrix that is the inverse of 'x'
24+ s <- x $ getsolve()
25+ if (! is.null(s )) {
26+ message(" getting cached data" )
27+ return (s )
28+ }
29+ data <- x $ get()
30+ s <- solve(data , ... )
31+ x $ setsolve(s )
32+ s
1533}
You can’t perform that action at this time.
0 commit comments