File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change 44# # Write a short comment describing this function
55
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
1121# # Write a short comment describing this function
1222
1323cacheSolve <- function (x , ... ) {
1424 # # Return a matrix that is the inverse of 'x'
25+ s <- x $ getsolve()
26+ if (! is.null(s )) {
27+ message(" getting cached data" )
28+ return (s )
29+ }
30+ data <- x $ get()
31+ s <- solve(data , ... )
32+ x $ setsolve(s )
33+ s
1534}
35+
36+ # m <- matrix(sample.int(100,size=9,replace=TRUE), nrow=3)
37+ # m
38+ # d <- makeCacheMatrix(m)
39+ # cacheSolve(d)
40+ # d$set(m)
41+ # cacheSolve(d)
You can’t perform that action at this time.
0 commit comments