File tree 1 file changed +25
-7
lines changed
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.
5
3
4
+ # # Make a matrix which can store a value for its inverse
5
+ # # instead of solving for it every time.
6
6
makeCacheMatrix <- 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 )
8
18
}
9
19
10
20
11
- # # Write a short comment describing this function
12
-
21
+ # # Calculate and cache the inverse of a matrix.
13
22
cacheSolve <- function (x , ... ) {
14
23
# # 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
15
33
}
You can’t perform that action at this time.
0 commit comments