File tree Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change 22# # functions do
33
44# # Write a short comment describing this function
5+ # #crete a with makeCacheMatrix framework
6+ # # > a<- makeCacheMatrix()
7+ # #create Matrix
8+ # # > a$set(1:4, 2)
9+ # #inspect Matrix
10+ # # > a$get()
11+ # # run cachesolve(a) to see if the results are cached
12+ # # > cachesolve(a)
13+ # # Run again to see cached results
14+ # # > cachesolve(a)
515
616makeCacheMatrix <- function (x = matrix ()) {
7-
17+ m <- NULL
18+ set <- function (y ,z ) {
19+ x <<- matrix (y , nrow = z )
20+ m <<- NULL
21+ }
22+ get <- function () x
23+ setmatrix <- function (solve ) m <<- solve
24+ getmatrix <- function () m
25+ list (set = set , get = get ,
26+ setmatrix = setmatrix ,
27+ getmatrix = getmatrix )
828}
929
1030
1131# # Write a short comment describing this function
1232
1333cacheSolve <- function (x , ... ) {
1434 # # Return a matrix that is the inverse of 'x'
35+ m <- x $ getmatrix()
36+ if (! is.null(m )) {
37+ message(" getting cached data" )
38+ return (m )
39+ }
40+ data <- x $ get()
41+ m <- solve(data , ... )
42+ x $ setmatrix(m )
43+ m
1544}
You can’t perform that action at this time.
0 commit comments